Cabal Common Library Doc 2DCollision

From Elite Wiki
Revision as of 12:29, 16 March 2012 by Svengali (talk | contribs) (Profiling added)

Overview

This is the main class for the 2D helpers with its members. Scripts can instantiate a copy, e.g.

this.myHelper = new Cabal_Common_2DCollision();

Properties

internalVersion

Number. Property to give OXPs a chance to check the required lib min. version easily. This number will be raised with every release.

var a = this.myHelper.internalVersion;

a -> 15

Methods

All methods are ignoring the z-coordinate .-)

boundingBox()

boundingBox: function( minmax, pos )
Profiler
Native 0.000042s
Extension 0.000013s
JS 0.000136s

Checks if point is inside the bounding box.

Parameters:

minmax
Array. 4 positions in a.x,a.y,b.x,b.y
pos
Vector. Position to be checked.

Returns:

inside
Boolean. True if inside.


pointInPoly()

pointInPoly: function( nvert, vertx, verty, pos, con )
Profiler
Native 0.000042s
Extension 0.000012s
JS 0.000101s

Checks if a point is inside a polygon.

Parameters:

nvert
Number of vertices in the polygon.
vertx, verty
Arrays containing the x- and y-coordinates of the polygon's vertices.
pos
Vector. x- and y-coordinate of the test point.
con
Boolean. Concave shapes may need to set it.

Returns:

inside
Boolean. True if inside.


pointOnLine()

pointOnLine: function( pa, pb, pos )
Profiler
Native 0.000240s
Extension 0.000123s
JS 0.000252s

Checks if point is on a specified line with a tolerance of 0.4. This method has a problem with vertical lines. If it needs to be more accurate use .pointOnLineB().

Parameters:

pa
Vector. Starting point of the line.
pb
Vector. End point of the line.
pos
Vector. Position to be checked.

Returns:

online
Boolean. True if on line (within tolerance).


pointOnLineB()

pointOnLineB: function( p1,p2,p3,tol )
Profiler
Native 0.000272s
Extension 0.000141s
JS 0.000303s

Checks if point is on a specified line. Based on Paul Bourkes explanation ([1]).

Parameters:

p1
Vector. Starting point of the line.
p2
Vector. End point of the line.
p3
Vector. Position to be checked.
tol
Number. Tolerance. Default 0.01.

Returns:

online
Boolean. True if on line (within tolerance).