Click or drag to resize
CollisionDetectorCheckCollision Method (GraphicComponent, GraphicComponent, Double)
Calculates whether two objects intersect, or whether an object intersects any other object.

Namespace:  ABB.Robotics.RobotStudio.Stations
Assembly:  ABB.Robotics.RobotStudio.Stations (in ABB.Robotics.RobotStudio.Stations.dll) Version: 7.0.8747.636
Syntax
C#
public static CollisionType CheckCollision(
	GraphicComponent object1,
	GraphicComponent object2,
	double nearMiss
)

Parameters

object1
Type: ABB.Robotics.RobotStudio.StationsGraphicComponent
First object.
object2
Type: ABB.Robotics.RobotStudio.StationsGraphicComponent
Second object.
nearMiss
Type: SystemDouble
Near miss distance.

Return Value

Type: CollisionType
A value indicating whether the objects collide or are closer than the near miss distance.
Remarks
If either object1 or object2 is NULL, it is checked against all other objects in the stations.
Examples
Check Collision.
CollisionDetection Example
public void CollisionDetection()
{
    Project.UndoContext.BeginUndoStep("CollisionDetection");
    try
    {
        Station station = Station.ActiveStation;

        #region CollisionDetectionPoint1
        // Create two parts and bodies to use in collision detection.
        Part p1 = new Part();
        p1.Name = "My Part1";
        Part p2 = new Part();
        p2.Name = "My Part2";
        station.GraphicComponents.Add(p1);
        station.GraphicComponents.Add(p2);
        #endregion

        // Create two boxes.
        Body box1 = Body.CreateSolidBox(new Matrix4(Vector3.XVector, 0.0),
            new Vector3(0.1, 0.1, 0.1));
        box1.Name = "My Box1";
        Body box2 = Body.CreateSolidBox(new Matrix4(Vector3.XVector, 0.0),
            new Vector3(0.1, 0.1, 0.1));
        box2.Name = "My Box2";

        // Move box2 0.105 meters along the X-axis .
        box2.Transform.X = box2.Transform.X + 0.105;

        // Add the boxes to the bodies.
        p1.Bodies.Add(box1);
        p2.Bodies.Add(box2);

        // Manually check to see if there is a collision between the two parts.
        // Also tests for a near miss, defined as being within 0.01 meter from each other.

        #region CollisionDetectionPoint2

        CollisionType colType = CollisionDetector.CheckCollision(p1, p2, 0.01);
        switch (colType)
        {
            case CollisionType.Collision:
                Logger.AddMessage(new LogMessage("Part: " + p1.Name
                    + " and part: " + p2.Name + " is colliding!"));
                break;
            case CollisionType.NearMiss:
                Logger.AddMessage(new LogMessage("There is a near miss between part: "
                    + p1.Name
                    + " and part: " + p2.Name + "."));
                Vector3 p1Point;
                Vector3 p2Point;
                Logger.AddMessage(new LogMessage("The distance between them are: "
                    + CollisionDetector.MinimumDistance(p1, p2, out p1Point, out p2Point)));
                Logger.AddMessage(new LogMessage("The closest points are: "));
                Logger.AddMessage(new LogMessage("For part: " + p1.Name + " x: " + p1Point.x
                    + " y: " + p1Point.y + " z: " + p1Point.z));
                Logger.AddMessage(new LogMessage("For part: " + p2.Name + " x: " + p2Point.x
                    + " y: " + p2Point.y + " z: " + p2Point.z));
                break;
            case CollisionType.None:
                Logger.AddMessage(new LogMessage("There is no collision!"));
                break;
        }
        #endregion

        // Reset the collision sets and highlights.
        CollisionDetector.ResetCollisions();

        // Add an event handler to the collision event.
        CollisionDetector.Collision += new CollisionEventHandler(myCollisionEventHandler);

        // Activate auto check for collisions each time the graphics is updated.
        CollisionDetector.AutoCheck = true;

        // Test for collisions on polygon level, not just for the bounding boxes.
        CollisionDetector.FastCheck = false;

        #region CollisionDetectionPoint3

        // Add the two boxes to a collision set.
        CollisionSet cs = new CollisionSet();
        cs.Name = "My CollisionSet";

        // Set the near miss distance to 0.01 meters.
        cs.NearMissDistance = 0.01;

        // Set the near miss color to black.
        cs.NearMissColor = System.Drawing.Color.Black;

        // Activate this collision set for collision checks.
        cs.Active = true;

        // Set the collision color to semi-transparent yellow.
        cs.CollisionColor = Color.FromArgb(128, System.Drawing.Color.Yellow);

        // Turn on highlighting of colliding objects.
        cs.Highlight = true;

        // Add the collision set to the station.
        station.CollisionSets.Add(cs);

        // Add the two parts to the two different collision object collections of the collision set.
        cs.FirstGroup.Add(p1);
        cs.SecondGroup.Add(p2);

        #endregion

        #region CollisionDetectionPoint4
        // Force check the station for collisions.
        CollisionDetector.CheckCollisions(station);

        // Force check the collision set for collisiosn.
        CollisionDetector.CheckCollisions(cs);
        #endregion

        // Freehand move the boxes in the graphics.
        // Notice the messages generated by the event handler code,
        // and the change in color of the boxes.
    }
    catch
    {
        Project.UndoContext.CancelUndoStep(CancelUndoStepType.Rollback);
        throw;
    }
    finally
    {
        Project.UndoContext.EndUndoStep();
    }
}

private void myCollisionEventHandler(object sender, CollisionEventArgs e)
{
    switch (e.CollisionEvent)
    {
        case CollisionEvent.CollisionStarted:
            Logger.AddMessage
            (new LogMessage("Collision started by collision set: '" + e.CollisionSet.Name
            + "' First part : '" + e.FirstPart.Name
            + "' Second part: '" + e.SecondPart.Name + "'"));
            break;
        case CollisionEvent.CollisionEnded:
            Logger.AddMessage(new LogMessage("Collision ended by collision set: '" + e.CollisionSet.Name
            + "' First part : '" + e.FirstPart.Name
            + "' Second part: '" + e.SecondPart.Name + "'"));
            break;
        case CollisionEvent.NearMissStarted:
            Logger.AddMessage(new LogMessage("Near Miss started by collision set: '" + e.CollisionSet.Name
            + "' First part : '" + e.FirstPart.Name
            + "' Second part: '" + e.SecondPart.Name + "'"));
            break;
        case CollisionEvent.NearMissEnded:
            Logger.AddMessage(new LogMessage("Near Miss ended by collision set: '" + e.CollisionSet.Name
            + "' First part : '"
            + e.FirstPart.Name + "' Second part: '" + e.SecondPart.Name + "'"));
            break;
        default:
            break;
    }
}
Version Information

Supported in: 1.0.0.0
See Also