Class CollisionDetector
Provides collision detection on Collision Sets.
Namespace: ABB.Robotics.RobotStudio.Stations
Assembly: ABB.Robotics.RobotStudio.Stations.dll
Syntax
public sealed class CollisionDetector
Remarks
All methods use the graphical (triangulated) representation of objects, which means the results are approximate.
Constructors
CollisionDetector()
ABB internal use.
Declaration
public CollisionDetector()
Properties
AutoCheck
Gets or sets a value indicating whether to check for collisions whenever the graphic model is updated.
Declaration
public static bool AutoCheck { get; set; }
Property Value
Type | Description |
---|---|
Boolean |
Examples
Get/Set AutoCheck.
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;
}
}
FastCheck
Gets or sets a value indicating whether to perform collision check only on bounding boxes and not on triangles.
Declaration
public static bool FastCheck { get; set; }
Property Value
Type | Description |
---|---|
Boolean |
Examples
Get/Set FastCheck.
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;
}
}
Methods
CheckCollision(TemporaryGraphic, Double, out Part)
Calculates whether any object in the active Station intersects with a TemporaryGraphic object.
Declaration
public static CollisionType CheckCollision(TemporaryGraphic tempGfx, double nearMiss, out Part part)
Parameters
Type | Name | Description |
---|---|---|
TemporaryGraphic | tempGfx | TemporaryGraphic object |
Double | nearMiss | Near miss distance. |
Part | part | Returns the Part that the TemporaryGraphic object intersects with. |
Returns
Type | Description |
---|---|
CollisionType | A value indicating whether the objects collide or are closer than the near miss distance. |
Remarks
The TemporaryGraphic object must be a triangular object (e.g. box, cylinder, sphere).
CheckCollision(GraphicComponent, TemporaryGraphic, Double)
Calculates whether an object intersects with a TemporaryGraphic object.
Declaration
public static CollisionType CheckCollision(GraphicComponent object1, TemporaryGraphic object2, double nearMiss)
Parameters
Type | Name | Description |
---|---|---|
GraphicComponent | object1 | GraphicComponent object. |
TemporaryGraphic | object2 | TemporaryGraphic object. |
Double | nearMiss | Near miss distance. |
Returns
Type | Description |
---|---|
CollisionType | A value indicating whether the objects collide or are closer than the near miss distance. |
Remarks
The TemporaryGraphic object must be a triangular object (e.g. box, cylinder, sphere).
Examples
Check Collision.
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;
}
}
CheckCollision(GraphicComponent, GraphicComponent, Double)
Calculates whether two objects intersect, or whether an object intersects any other object.
Declaration
public static CollisionType CheckCollision(GraphicComponent object1, GraphicComponent object2, double nearMiss)
Parameters
Type | Name | Description |
---|---|---|
GraphicComponent | object1 | First object. |
GraphicComponent | object2 | Second object. |
Double | nearMiss | Near miss distance. |
Returns
Type | Description |
---|---|
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.
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;
}
}
CheckCollision(GraphicComponent, GraphicComponent, Double, DetectableUsage, out Part, out Part)
Calculates whether two objects intersect, or whether an object intersects any other object, and returns the intersecting Parts.
Declaration
public static CollisionType CheckCollision(GraphicComponent object1, GraphicComponent object2, double nearMiss, DetectableUsage detectableUsage, out Part part1, out Part part2)
Parameters
Type | Name | Description |
---|---|---|
GraphicComponent | object1 | First object. |
GraphicComponent | object2 | Second object. |
Double | nearMiss | Near miss distance. |
DetectableUsage | detectableUsage | Specifies how the Detectable property is used when checking for collision between two GraphicComponents. |
Part | part1 | Part in first object. |
Part | part2 | Part in second object. |
Returns
Type | Description |
---|---|
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.
CheckCollision(GraphicComponent, GraphicComponent, Double, DetectableUsage, Boolean, out Part, out Part)
Calculates whether two objects intersect, or whether an object intersects any other object, and returns the intersecting Parts.
Declaration
public static CollisionType CheckCollision(GraphicComponent object1, GraphicComponent object2, double nearMiss, DetectableUsage detectableUsage, bool excludeInvisible, out Part part1, out Part part2)
Parameters
Type | Name | Description |
---|---|---|
GraphicComponent | object1 | First object. |
GraphicComponent | object2 | Second object. |
Double | nearMiss | Near miss distance. |
DetectableUsage | detectableUsage | Specifies how the Detectable property is used when checking for collision between two GraphicComponents. |
Boolean | excludeInvisible | Do not include invisible objects when checking for collision. |
Part | part1 | Part in first object. |
Part | part2 | Part in second object. |
Returns
Type | Description |
---|---|
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.
CheckCollision(GraphicComponent, GraphicComponent, Double, DetectableUsage, Boolean, Boolean, out Part, out Part)
Calculates whether two objects intersect, or whether an object intersects any other object, and returns the intersecting Parts.
Declaration
public static CollisionType CheckCollision(GraphicComponent object1, GraphicComponent object2, double nearMiss, DetectableUsage detectableUsage, bool excludeInvisible1, bool excludeInvisible2, out Part part1, out Part part2)
Parameters
Type | Name | Description |
---|---|---|
GraphicComponent | object1 | First object. |
GraphicComponent | object2 | Second object. |
Double | nearMiss | Near miss distance. |
DetectableUsage | detectableUsage | Specifies how the Detectable property is used when checking for collision between two GraphicComponents. |
Boolean | excludeInvisible1 | Do not include invisible objects in object1 when checking for collision. |
Boolean | excludeInvisible2 | Do not include invisible objects in object2 when checking for collision. |
Part | part1 | Part in first object. |
Part | part2 | Part in second object. |
Returns
Type | Description |
---|---|
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.
CheckCollision(GraphicComponent, GraphicComponent, Double, out Part, out Part)
Calculates whether two objects intersect, or whether an object intersects any other object, and returns the intersecting Parts.
Declaration
public static CollisionType CheckCollision(GraphicComponent object1, GraphicComponent object2, double nearMiss, out Part part1, out Part part2)
Parameters
Type | Name | Description |
---|---|---|
GraphicComponent | object1 | First object. |
GraphicComponent | object2 | Second object. |
Double | nearMiss | Near miss distance. |
Part | part1 | Part in first object. |
Part | part2 | Part in second object. |
Returns
Type | Description |
---|---|
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.
CheckCollisions(CollisionSet)
Check collisions for a collision set.
Declaration
public static void CheckCollisions(CollisionSet collisionSet)
Parameters
Type | Name | Description |
---|---|---|
CollisionSet | collisionSet | The Station to check for collisions. |
Examples
Check Collision Set for collisions.
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;
}
}
CheckCollisions(Station)
Check collisions for all collision sets in the station.
Declaration
public static void CheckCollisions(Station station)
Parameters
Type | Name | Description |
---|---|---|
Station | station | The Station to check for collisions. |
Examples
Check Station for collissions.
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;
}
}
CheckLineIntersection(Station, Vector3, Vector3, Double, out Part, out Vector3)
Calculates whether an line between two points intersects with any graphical object in a station.
Declaration
public static bool CheckLineIntersection(Station station, Vector3 start, Vector3 end, double radius, out Part closestPart, out Vector3 intersectionPoint)
Parameters
Type | Name | Description |
---|---|---|
Station | station | The Station to check for intersection. |
Vector3 | start | Start point of the intersection line. |
Vector3 | end | End point of the intersection line. |
Double | radius | Radius of the intersection line. |
Part | closestPart | Returns the intersecting Part closest to the start point. |
Vector3 | intersectionPoint | Returns the intersection point. |
Returns
Type | Description |
---|---|
Boolean | A value indicating whether any object intersects with the line. |
Remarks
If radius is not zero, the returned intersection point will be approximate.
MinimumDistance(ProjectObject, ProjectObject, out Vector3, out Vector3)
Calculates the shortest distance between two graphic objects, as well as the closest points on the objects.
Declaration
public static double MinimumDistance(ProjectObject object1, ProjectObject object2, out Vector3 point1, out Vector3 point2)
Parameters
Type | Name | Description |
---|---|---|
ProjectObject | object1 | First object. Must be GraphicComponent, Body or Face. |
ProjectObject | object2 | Second object. Must be GraphicComponent, Body or Face. |
Vector3 | point1 | Returns the closest point on the first object. |
Vector3 | point2 | Returns the closest point on the second object. |
Returns
Type | Description |
---|---|
Double | The shortest distance between the objects. |
Remarks
The algorithm uses the graphical representation of objects, so the result is an approximation.
Examples
MinimumDistance.
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;
}
}
MinimumDistance(ProjectObject, ProjectObject, out Vector3, out Vector3, out Part, out Part)
Calculates the shortest distance between two graphic objects, as well as the closest points on the objects.
Declaration
public static double MinimumDistance(ProjectObject object1, ProjectObject object2, out Vector3 point1, out Vector3 point2, out Part part1, out Part part2)
Parameters
Type | Name | Description |
---|---|---|
ProjectObject | object1 | First object. Must be GraphicComponent, Body or Face. |
ProjectObject | object2 | Second object. Must be GraphicComponent, Body or Face. |
Vector3 | point1 | Returns the closest point on the first object. |
Vector3 | point2 | Returns the closest point on the second object. |
Part | part1 | Returns the closest Part in the first object. |
Part | part2 | Returns the closest Part in the second object. |
Returns
Type | Description |
---|---|
Double | The shortest distance between the objects, or -1 if the calculation fails. |
Remarks
The algorithm uses the graphical representation of objects, so the result is an approximation.
Examples
MinimumDistance.
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;
}
}
MinimumDistance(ProjectObject, ProjectObject, out Vector3, out Vector3, out Part, out Part, DetectableUsage)
Calculates the shortest distance between two graphic objects, as well as the closest points on the objects.
Declaration
public static double MinimumDistance(ProjectObject object1, ProjectObject object2, out Vector3 point1, out Vector3 point2, out Part part1, out Part part2, DetectableUsage detectableUsage)
Parameters
Type | Name | Description |
---|---|---|
ProjectObject | object1 | First object. Must be GraphicComponent, Body or Face. |
ProjectObject | object2 | Second object. Must be GraphicComponent, Body or Face. |
Vector3 | point1 | Returns the closest point on the first object. |
Vector3 | point2 | Returns the closest point on the second object. |
Part | part1 | Returns the closest Part in the first object. |
Part | part2 | Returns the closest Part in the second object. |
DetectableUsage | detectableUsage | Specifies how the Detectable property is used when checking distance between two GraphicComponents. |
Returns
Type | Description |
---|---|
Double | The shortest distance between the objects, 0 if the objects intersect or -1 if the calculation fails. |
Remarks
The algorithm uses the graphical representation of objects, so the result is an approximation.
Examples
MinimumDistance.
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;
}
}
PointDistance(Vector3, ProjectObject, out Vector3, out Part)
Calculates the shortest distance from a point to a graphic object, as well as the closest point on the object.
Declaration
public static double PointDistance(Vector3 testPoint, ProjectObject testObject, out Vector3 hitPoint, out Part hitPart)
Parameters
Type | Name | Description |
---|---|---|
Vector3 | testPoint | Point to test (in world coordinates) |
ProjectObject | testObject | Object to test. Must be GraphicComponent, Body or Face. |
Vector3 | hitPoint | Returns the closest point on the object. |
Part | hitPart | Returns the part where the closest point is. |
Returns
Type | Description |
---|---|
Double | The shortest distance between the point and the objects, or -1 if the calculation fails. |
Remarks
The algorithm uses the graphical representation of objects, so the result is an approximation.
PointDistance(Vector3, ProjectObject, out Vector3, out Part, Boolean)
Calculates the shortest distance from a point to a graphic object, as well as the closest point on the object.
Declaration
public static double PointDistance(Vector3 testPoint, ProjectObject testObject, out Vector3 hitPoint, out Part hitPart, bool checkDetectable)
Parameters
Type | Name | Description |
---|---|---|
Vector3 | testPoint | Point to test (in world coordinates) |
ProjectObject | testObject | Object to test. Must be GraphicComponent, Body or Face. |
Vector3 | hitPoint | Returns the closest point on the object. |
Part | hitPart | Returns the part where the closest point is. |
Boolean | checkDetectable | Skip objects with the Detectable flag set to false. |
Returns
Type | Description |
---|---|
Double | The shortest distance between the point and the objects, or -1 if the calculation fails. |
Remarks
The algorithm uses the graphical representation of objects, so the result is an approximation.
ResetCollisions()
Reset collisions, highlights and markups.
Declaration
public static void ResetCollisions()
Examples
Reset Collisions.
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;
}
}
ResetCollisions(CollisionSet)
Reset collisions and highlights for a collision set.
Declaration
public static void ResetCollisions(CollisionSet collisionSet)
Parameters
Type | Name | Description |
---|---|---|
CollisionSet | collisionSet |
Events
Collision
Occurs when a collision starts, ends or changes type.
Declaration
public static event CollisionEventHandler Collision
Event Type
Type | Description |
---|---|
CollisionEventHandler |
Examples
Collision event.
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;
}
}