vcCollisionDetector

vcCollisionDetector is a layout item used for detecting the collision of objects in the 3D world. A collision test can detect a collision using geometry in different nodes and/or a bound box defined by two corner points.

Generally, a collision detector compares the geometry in two node lists. It tests if the geometry in one list collides with geometry in another list. A tolerance/minimum distance can be used to detect a collision before it occurs in the 3D world. A collision detector can test for the first collision or all collisions between nodes in both lists.

If you use a bound box, one point defines the bottom left corner of the box, and the other point defines the upper right corner of the box. Also, consider using a volume detector instead of a collision detector.

Inherits: vcLayoutItem

Properties

Name Type Access Description
Active Boolean RW Turns on/off the use of collision test.
CollisionMaterial vcMaterial RW Get/Set material of the collided node.
DisplayMinimumDistance Boolean RW Turns on/off the display of minimum distance in the 3D world between objects in a collision test that uses a distance tolerance greater than zero.
HitCount Integer R Gets the number of detected collisions.
IgnoreClosestNodes Boolean RW Ignores collisions between two nodes if a node is either parent or child to the other node. This can be used to test self-collision of a component. Default value is False.
IgnoreDifferentComponents Boolean RW Ignores collisions between nodes when they are on different components. This can be used to test multiple self-collisions of components. Default value is False.
NodeBCollisionMaterial vcMaterial RW Get/Set material of the collided node B. This property will define the node B material over CollisionMaterial.
NodeListA List of 3-tuple (vcNode node, Enumeration type, Enumeration inclusion_scope) RW Defines a list of nodes to compare with NodeListB.

See Collision Detector Constants for more information.

NodeListB List of 3-tuple (vcNode node, Enumeration inclusion_type, Enumeration inclusion_scope) RW Defines a list of nodes to compare with NodeListA.

See Collision Detector Constants for more information.

Tolerance Real RW Defines a distance tolerance for detecting collisions before objects in the test collide with one another.   Note that if Tolerance is set to zero, a simplified collision detection algorithm is used. This algorithm does not detect collisions if one geometry is completely enclosed by the other, so for example, if the bounding box surfaces do not intersect.

Methods

Name Return Type Parameters Description
getBBoxGeometry vcPolygonSet vcVector corner1, vcVector corner2, [vcMatrix transformation] Returns a bound box defined by given corner points as a set of geometry.

An optional transformation argument can be given to transform the bound box using World coordinates.

getHitFeatureA vcFeature Integer index Returns the feature in NodeListA in the detected collision.
getHitFeatureB vcFeature Integer index Returns the feature in NodeListB in the detected collision.
getHitGeometrySetA vcGeometrySet Integer index Returns the geometry set in NodeListA in the detected collision.
getHitGeometrySetB vcGeometrySet Integer index Returns the geometry set in NodeListB in the detected collision.
getHitNodeA vcNode Integer index Returns the node in NodeListA in the detected collision.
getHitNodeB vcNode Integer index Returns the node in NodeListB in the detected collision.
getMinimumDistanceDistance Real Integer index Returns the distance between objects in a detected collision when testing with a tolerance/minimum distance.
getMinimumDistancePoint1 vcVector Integer index Returns the point in NodeListA in a detected collision when using a tolerance.
getMinimumDistancePoint2 vcVector Integer index Returns the point in NodeListB in a detected collision when using a tolerance.
testAllBBoxCollisions Boolean vcVector corner1, vcVector corner2, [vcMatrix transformation], [Real tolerance] Returns true if any collision between NodeListA and a bound box defined by given corner points.

An optional transformation argument can be given to transform the bound box using World coordinates.

If no tolerance is given, test uses zero distance.

testAllCollisions Boolean [Real tolerance] Returns true if any collision between NodeListA and NodeListB.

If no tolerance is given, test uses zero distance.

testBBoxComponentCollisions Boolean vcVector corner1, vcVector corner2, [vcMatrix bbox_reference] Returns true if a component collides with a bound box defined by given corner points.

An optional bbox_reference argument can be given to transform the bound box using World coordinates.

testBBoxNodeCollisions Boolean vcVector corner1, vcVector corner2, [vcMatrix bbox_reference] Returns true if a node collides with a bound box defined by given corner points.

An optional bbox_reference argument can be given to transform the bound box using World coordinates.

testComponentCollisions Boolean None Returns true if collision detected with component.
testMinimumDistance Boolean Real tolerance Returns true if collision detected with a given tolerance value.
testNodeCollisions Boolean None Returns true if collision detected with node.
testOneBBoxCollision Boolean vcVector corner1, vcVector corner2, [vcMatrix transformation], [Real tolerance] Returns true for first collision between NodeListA and a bound box defined by given corner points.

An optional transformation argument can be given to transform the bound box using World coordinates.

If no tolerance is given, test uses zero distance.

testOneCollision Boolean [Real tolerance] Returns true for first collision between NodeListA and NodeListB.

If no tolerance is given, test uses zero distance.

Events

Name Parameters Description

OnCollision

vcCollisionDetector detector

Triggered when a collision is detected and test is active.

Examples

Example. Detecting if gripper (or anything the gripper is holding) collides with something

from vcScript import *

def OnSignal( signal ):

  pass

def OnRun():

  detector = simu.newCollisionDetector()

  detector.NodeListA = [(gripper_node, VC_NODELIST_INCLUDE, VC_NODELIST_TREE )]

  detector.NodeListB = [(simu.World, VC_NODELIST_INCLUDE, VC_NODELIST_TREE ),(Component_,

VC_NODELIST_EXCLUDE, VC_NODELIST_TREE )]

  while True:

    delay(0.1)

    hit = detector.testOneCollision(0.1)

    if hit:

      #part = detector.Component < --------------- please remove

      print 'collision detected'

simu = getSimulation()

app = getApplication()

gripper_node = getComponent()

Component_ = app.findComponent('BinPartBlockTemplate')

Example. Detecting collisions using a minimum distance tolerance

node1.update()

node2.update()

sim = getSimulation()

detector = sim.newCollisionDetector()

detector.NodeListA = [ (node1, VC_NODELIST_INCLUDE, VC_NODELIST_TREE ) ]

detector.NodeListB = [ (node2, VC_NODELIST_INCLUDE, VC_NODELIST_TREE ) ]

hit = detector.testMinimumDistance( some_dist )

print 'Minimum distance: %f mm' % detector.getMinimumDistanceDistance( 0 )

v1 = detector.getMinimumDistancePoint1( 0 )

v2 = detector.getMinimumDistancePoint2( 0 )

line_set = sim.World.UserGeometry.createGeometrySet(VC_COMPACTLINESET)

line_set.addLine( [v1,v2] )

line_set.update()