Geom class provides interface to collision detection routines in nape.

Static methods

staticdistanceBody(body1:Body, body2:Body, out1:Vec2, out2:Vec2):Float

Determine distance and closest points between two Bodies.

If the bodies are intersecting, then a negative value is returned equal to the penetration of the bodies, and the out1/out2 vectors will still be meaningful with their difference being the minimum translational vector to seperate the intersecting shapes of the bodies. (This may not be a global seperation vector as it is considering only one pair of shapes at a time).

As the out1/out2 vectors are used to return values from the function, this is one of the rare cases where should out1/out2 be weak Vec2's they will 'not' be sent to the global object pool on being passed to this function.

var closest1 = Vec2.get();
var closest2 = Vec2.get();
var distance = Geom.distanceBody(body1, body2, out1, out2);
if (distance < 0) {

trace("Bodies intersect and penetration distance is " +
      (-distance) + " with witness points " + closest1.toString() +
      " <-> " + closest2.toString());

}else {

trace("Bodies do not intersect and distance betweem them is " +
      distance + " with closest points " + closest1.toString() +
      " <-> " + closest2.toString());

}

This algorithm is able to take shortcuts in culling pair tests between Shapes based on the current state of the search, and will be more effecient than a custom implementation that uses Geom.distance(..) method.

Parameters:

body1

First input Body.

body2

Second input Body.

out1

This Vec2 object will be populated with coordinates of closest point on body1.

out2

This Vec2 object will be populated with coordinates of closest point on body2.

Returns:

The distance between the two bodies if seperated, or the penetration distance (negative) if intersecting.

Throws:

#

If either body has no shapes.

#

If out1 or out2 has been disposed.

#

If out1 or out2 is immutable.

staticdistance(shape1:Shape, shape2:Shape, out1:Vec2, out2:Vec2):Float

Determine distance and closest points between two Shapes.

The input Shapes must belong to a Body so that their world positions and orientations are defined; these Bodies need not be different nor part of any Space.

If the shapes are intersecting, then a negative value is returned equal to the penetration of the shapes, and the out1/out2 vectors will still be meaningful with their difference being the minimum translational vector to seperate the Shapes.

As the out1/out2 vectors are used to return values from the function, this is one of the rare cases where should out1/out2 be weak Vec2's they will 'not' be sent to the global object pool on being passed to this function.

var closest1 = Vec2.get();
var closest2 = Vec2.get();
var distance = Geom.distance(shape1, shape2, out1, out2);
if (distance < 0) {

trace("Shapes intersect and penetration distance is " +
      (-distance) + " with witness points " + closest1.toString() +
      " <-> " + closest2.toString());

}else {

trace("Shapes do not intersect and distance betweem them is " +
      distance + " with closest points " + closest1.toString() +
      " <-> " + closest2.toString());

}

Parameters:

shape1

this shape must belong to a Body.

shape2

this shape must belong to a Body.

out1

This Vec2 object will be populated with coordinates of closest point on shape1.

out2

This Vec2 object will be populated with coordinates of closest point on shape2.

Returns:

The distance between the two shapes if seperated, or the penetration distance (negative) if intersecting.

Throws:

#

If shape1.body is null or shape2.body is null.

#

If out1 or out2 has been disposed.

#

If out1 or out2 is immutable.

staticintersectsBody(body1:Body, body2:Body):Bool

Determine if two Bodies intersect.

If you do not need distance/penetration information, then using this method will be more effecient than testing for a negative value using the distance method.

Parameters:

body1

First input Body .

body2

Second input Body.

Returns:

True if the Bodies are intersecting.

Throws:

#

If either body has no shapes.

staticintersects(shape1:Shape, shape2:Shape):Bool

Determine if two Shapes intersect.

The input Shapes must belong to a Body so that their world positions and orientations are defined; these Bodies need not be different nor part of any Space.

If you do not need distance/penetration information, then using this method will be more effecient than testing for a negative value using the distance method.

Parameters:

shape1

this shape must belong to a Body.

shape2

this shape must belong to a Body.

Returns:

True if the shapes are intersecting in world space.

Throws:

#

If shape1.body or shape2.body is null.

staticcontains(shape1:Shape, shape2:Shape):Bool

Determine if one Shape is entirely contained within another.

The input Shapes must belong to a Body so that their world positions and orientations are defined; these Bodies need not be different nor part of any Space.

Parameters:

shape1

this shape must belong to a Body.

shape2

this shape must belong to a Body.

Returns:

True if shape2 is completely contained within shape1.

Throws:

#

If shape1.body or shape2.body is null.