AI for Games 1.1.1
Loading...
Searching...
No Matches
game2dai.maths.Geometry2D Class Reference

Static Public Member Functions

static void point_to_line_dist (double nearness)
 
static boolean is_point_near_line (Vector2D v0, Vector2D v1, Vector2D p)
 
static boolean is_point_near_line (Vector2D v0, Vector2D v1, Vector2D p, Vector2D vp)
 
static boolean is_point_near_infinite_line (Vector2D v0, Vector2D v1, Vector2D p)
 
static boolean is_point_near_infinite_line (Vector2D v0, Vector2D v1, Vector2D p, Vector2D vp)
 
static Vector2D point_nearest_line (Vector2D v0, Vector2D v1, Vector2D p)
 
static Vector2D point_nearest_infinite_line (Vector2D v0, Vector2D v1, Vector2D p)
 
static boolean line_circle (double x0, double y0, double x1, double y1, double cx, double cy, double r)
 
static double[] line_circle_p (double x0, double y0, double x1, double y1, double cx, double cy, double r)
 
static boolean line_line (double x0, double y0, double x1, double y1, double x2, double y2, double x3, double y3)
 
static Vector2D line_line_p (Vector2D v0, Vector2D v1, Vector2D v2, Vector2D v3)
 
static Vector2D line_line_infinite_p (Vector2D v0, Vector2D v1, Vector2D v2, Vector2D v3)
 
static double[] line_line_p (double x0, double y0, double x1, double y1, double x2, double y2, double x3, double y3)
 
static double[] line_line_infinite_p (double x0, double y0, double x1, double y1, double x2, double y2, double x3, double y3)
 
static double[] line_lines_p (double x0, double y0, double x1, double y1, double[] xy, boolean continuous)
 
static boolean circle_circle (double cx0, double cy0, double r0, double cx1, double cy1, double r1)
 
static double[] circle_circle_p (double cx0, double cy0, double r0, double cx1, double cy1, double r1)
 
static double[] tangents_to_circle (double x, double y, double cx, double cy, double r)
 
static double[] tangents_between_circles (double cx0, double cy0, double r0, double cx1, double cy1, double r1)
 
static int which_side_pp (double x0, double y0, double x1, double y1, double px, double py)
 
static int which_side_pn (double x0, double y0, double nx, double ny, double px, double py)
 
static boolean line_box_xyxy (double lx0, double ly0, double lx1, double ly1, double rx0, double ry0, double rx1, double ry1)
 
static boolean line_box_xywh (double lx0, double ly0, double lx1, double ly1, double rx0, double ry0, double rWidth, double rHeight)
 
static boolean box_box (double ax0, double ay0, double ax1, double ay1, double bx0, double by0, double bx1, double by1)
 
static double[] box_box_p (double ax0, double ay0, double ax1, double ay1, double bx0, double by0, double bx1, double by1)
 
static boolean isInsideTriangle (double aX, double aY, double bX, double bY, double cX, double cY, double pX, double pY)
 
static boolean isInsideTriangle (Vector2D a, Vector2D b, Vector2D c, Vector2D p)
 
static boolean isInsideTriangle (Vector2D a, Vector2D b, Vector2D c, double pX, double pY)
 
static boolean isInsideRectangle_xyxy (double x0, double y0, double x1, double y1, double pX, double pY)
 
static boolean isInsideRectangle_xyxy (Vector2D v0, Vector2D v1, Vector2D p)
 
static boolean isInsideRectangle_xywh (double x0, double y0, double width, double height, double pX, double pY)
 
static boolean isInsideRectangle_xywh (Vector2D v0, double width, double height, Vector2D p)
 
static boolean isInsidePolygon (Vector2D[] verts, double x0, double y0)
 
static double distance_sq (double x0, double y0, double x1, double y1)
 
static double distance (double x0, double y0, double x1, double y1)
 

Static Public Attributes

static final int ON_PLANE = 16
 
static final int PLANE_INSIDE = 17
 
static final int PLANE_OUTSIDE = 18
 

Static Private Member Functions

static int outcode (double pX, double pY, double rectX, double rectY, double rectWidth, double rectHeight)
 

Static Private Attributes

static final double ACCY = 1E-30
 
static final double[] NONE = new double[0]
 
static final int OUT_LEFT = 1
 
static final int OUT_TOP = 2
 
static final int OUT_RIGHT = 4
 
static final int OUT_BOTTOM = 8
 
static double NEARNESS = 1.0
 

Member Function Documentation

◆ box_box()

static boolean game2dai.maths.Geometry2D.box_box ( double  ax0,
double  ay0,
double  ax1,
double  ay1,
double  bx0,
double  by0,
double  bx1,
double  by1 
)
static

Determine whether two boxes intersect.
The boxes are represented by the top-left and bottom-right corner coordinates.

Parameters
ax0top-left corner of rectangle A
ay0top-left corner of rectangle A
ax1bottom-right corner of rectangle A
ay1bottom-right corner of rectangle A
bx0top-left corner of rectangle B
by0top-left corner of rectangle B
bx1bottom-right corner of rectangle B
by1bottom-right corner of rectangle B
Returns
true if the boxes intersect

◆ box_box_p()

static double[] game2dai.maths.Geometry2D.box_box_p ( double  ax0,
double  ay0,
double  ax1,
double  ay1,
double  bx0,
double  by0,
double  bx1,
double  by1 
)
static

If two boxes overlap then the overlap region is another box. This method is used to calculate the coordinates of the overlap.
The boxes are represented by the top-left and bottom-right corner coordinates. If the returned array has a length: 0 then they do not overlap
4 then these are the coordinates of the top-left and bottom-right corners of the overlap region.

Parameters
ax0top-left corner of rectangle A
ay0top-left corner of rectangle A
ax1bottom-right corner of rectangle A
ay1bottom-right corner of rectangle A
bx0top-left corner of rectangle B
by0top-left corner of rectangle B
bx1bottom-right corner of rectangle B
by1bottom-right corner of rectangle B
Returns
an array with the overlap box coordinates (if any)

◆ circle_circle()

static boolean game2dai.maths.Geometry2D.circle_circle ( double  cx0,
double  cy0,
double  r0,
double  cx1,
double  cy1,
double  r1 
)
static

Determine if two circles overlap

Parameters
cx0centre of first circle x position
cy0centre of first circle y position
r0radius of first circle
cx1centre of second circle x position
cy1centre of second circle y position
r1radius of second circle
Returns
true if the circles overlap else false

◆ circle_circle_p()

static double[] game2dai.maths.Geometry2D.circle_circle_p ( double  cx0,
double  cy0,
double  r0,
double  cx1,
double  cy1,
double  r1 
)
static

Calculate the intersection points between two circles.
If the array is of length:
0 then there is no intersection
2 there is just one intersection (the circles are touching)
4 there are two intersections

Parameters
cx0centre of first circle x position
cy0centre of first circle y position
r0radius of first circle
cx1centre of second circle x position
cy1centre of second circle y position
r1radius of second circle
Returns
an array with the intersection points

◆ distance()

static double game2dai.maths.Geometry2D.distance ( double  x0,
double  y0,
double  x1,
double  y1 
)
static

Calculates the distance between 2 points

Parameters
x0point 1
y0point 1
x1point 2
y1point 2
Returns
the distance between the points squared

◆ distance_sq()

static double game2dai.maths.Geometry2D.distance_sq ( double  x0,
double  y0,
double  x1,
double  y1 
)
static

Calculates the squared distance between 2 points

Parameters
x0point 1
y0point 1
x1point 2
y1point 2
Returns
the distance between the points squared

◆ is_point_near_infinite_line() [1/2]

static boolean game2dai.maths.Geometry2D.is_point_near_infinite_line ( Vector2D  v0,
Vector2D  v1,
Vector2D  p 
)
static

See if point is near the infinite line.

Parameters
v0line passes through this point
v1line passes through this point
ppoint to consider
Returns
true if p is near the line

◆ is_point_near_infinite_line() [2/2]

static boolean game2dai.maths.Geometry2D.is_point_near_infinite_line ( Vector2D  v0,
Vector2D  v1,
Vector2D  p,
Vector2D  vp 
)
static

See if point is near the infinite line.

Parameters
v0line passes through this point
v1line passes through this point
ppoint to consider
vpfilled with xy position of the nearest point on line (must not be null)
Returns
true if p is near the line

◆ is_point_near_line() [1/2]

static boolean game2dai.maths.Geometry2D.is_point_near_line ( Vector2D  v0,
Vector2D  v1,
Vector2D  p 
)
static

See if point is near the finite line.

Parameters
v0line start
v1line end
ppoint to consider
Returns
true if p is near the line

◆ is_point_near_line() [2/2]

static boolean game2dai.maths.Geometry2D.is_point_near_line ( Vector2D  v0,
Vector2D  v1,
Vector2D  p,
Vector2D  vp 
)
static

See if point is near the finite line.

Parameters
v0line start
v1line end
ppoint to consider
vpfilled with xy position of the nearest point on finite line (must not be null)
Returns
true if p is near the line

◆ isInsidePolygon()

static boolean game2dai.maths.Geometry2D.isInsidePolygon ( Vector2D[]  verts,
double  x0,
double  y0 
)
static

See if the given point is inside a polygon defined by the vertices provided.

Parameters
vertsthe vertices of the shape
x0
y0
Returns
true if x0, y0 is inside polygon else returns false

◆ isInsideRectangle_xywh() [1/2]

static boolean game2dai.maths.Geometry2D.isInsideRectangle_xywh ( double  x0,
double  y0,
double  width,
double  height,
double  pX,
double  pY 
)
static

See if a point is inside the rectangle defined by top-left and bottom right coordinates

Parameters
x0top-left corner of rectangle
y0top-left corner of rectangle
widthwidth of rectangle
heightheight of rectangle
pXx position of point of interest
pYy position of point of interest
Returns
true if inside rectangle else false

◆ isInsideRectangle_xywh() [2/2]

static boolean game2dai.maths.Geometry2D.isInsideRectangle_xywh ( Vector2D  v0,
double  width,
double  height,
Vector2D  p 
)
static

See if this a is inside the rectangle defined by top-left and bottom right coordinates

Parameters
v0top-left corner of rectangle
widthwidth of rectangle
heightheight of rectangle
ppoint of interest
Returns
true if inside rectangle else false

◆ isInsideRectangle_xyxy() [1/2]

static boolean game2dai.maths.Geometry2D.isInsideRectangle_xyxy ( double  x0,
double  y0,
double  x1,
double  y1,
double  pX,
double  pY 
)
static

See if a point is inside the rectangle defined by top-left and bottom right coordinates

Parameters
x0top-left corner of rectangle
y0top-left corner of rectangle
x1bottom-right corner of rectangle
y1bottom-right corner of rectangle
pXx position of point of interest
pYy position of point of interest
Returns
true if inside rectangle else false

◆ isInsideRectangle_xyxy() [2/2]

static boolean game2dai.maths.Geometry2D.isInsideRectangle_xyxy ( Vector2D  v0,
Vector2D  v1,
Vector2D  p 
)
static

See if this a is inside the rectangle defined by top-left and bottom right coordinates

Parameters
v0top-left corner of rectangle
v1bottom-right corner of rectangle
ppoint of interest
Returns
true if inside rectangle else false

◆ isInsideTriangle() [1/3]

static boolean game2dai.maths.Geometry2D.isInsideTriangle ( double  aX,
double  aY,
double  bX,
double  bY,
double  cX,
double  cY,
double  pX,
double  pY 
)
static

Determine if the point pX/pY is inside triangle defined by triangle ABC whose vertices are given by [ax,ay] [bx,by] [cx,cy]

Returns
true if the point is inside

◆ isInsideTriangle() [2/3]

static boolean game2dai.maths.Geometry2D.isInsideTriangle ( Vector2D  a,
Vector2D  b,
Vector2D  c,
double  pX,
double  pY 
)
static

Determine if the point pX/pY is inside triangle defined by triangle ABC

Parameters
atriangle vertex 1
btriangle vertex 2
ctriangle vertex 3
pXx position for point of interest
pYy position for point of interest
Returns
true if inside triangle else false

◆ isInsideTriangle() [3/3]

static boolean game2dai.maths.Geometry2D.isInsideTriangle ( Vector2D  a,
Vector2D  b,
Vector2D  c,
Vector2D  p 
)
static

Determine if the point (p) is inside triangle defined by triangle ABC

Parameters
atriangle vertex 1
btriangle vertex 2
ctriangle vertex 3
ppoint of interest
Returns
true if inside triangle else false

◆ line_box_xywh()

static boolean game2dai.maths.Geometry2D.line_box_xywh ( double  lx0,
double  ly0,
double  lx1,
double  ly1,
double  rx0,
double  ry0,
double  rWidth,
double  rHeight 
)
static

Determine whether a line intersects with a box.
The box is represented by the top-left corner coordinates and the box width and height.

Parameters
lx0start of line
ly0start of line
lx1end of line
ly1end of line
rx0top-left corner of rectangle
ry0top-left corner of rectangle
rWidthwidth of rectangle
rHeightheight of rectangle
Returns
true if they intersect else false

◆ line_box_xyxy()

static boolean game2dai.maths.Geometry2D.line_box_xyxy ( double  lx0,
double  ly0,
double  lx1,
double  ly1,
double  rx0,
double  ry0,
double  rx1,
double  ry1 
)
static

Determine whether a line intersects with a box.
The box is represented by the top-left and bottom-right corner coordinates.

Parameters
lx0start of line
ly0start of line
lx1end of line
ly1end of line
rx0top-left corner of rectangle
ry0top-left corner of rectangle
rx1bottom-right corner of rectangle
ry1bottom-right corner of rectangle
Returns
true if they intersect else false

◆ line_circle()

static boolean game2dai.maths.Geometry2D.line_circle ( double  x0,
double  y0,
double  x1,
double  y1,
double  cx,
double  cy,
double  r 
)
static

Sees if a line intersects with the circumference of a circle.

Parameters
x0
y0
x1
y1
cxcentre of circle x position
cycentre of circle y position
rradius of circle
Returns
true if the line intersects the circle else false

◆ line_circle_p()

static double[] game2dai.maths.Geometry2D.line_circle_p ( double  x0,
double  y0,
double  x1,
double  y1,
double  cx,
double  cy,
double  r 
)
static

Calculate the points of intersection between a line and a circle.
An array is returned that contains the intersection points in x, y order. If the array is of length:
0 then there is no intersection
2 there is just one intersection (the line is a tangent to the circle)
4 there are two intersections

Parameters
x0start of line
y0start of line
x1end of line
y1end of line
cxcentre of circle x position
cycentre of circle y position
rradius of circle
Returns
the intersection points as an array (2 elements per intersection)

◆ line_line()

static boolean game2dai.maths.Geometry2D.line_line ( double  x0,
double  y0,
double  x1,
double  y1,
double  x2,
double  y2,
double  x3,
double  y3 
)
static

See if two lines intersect

Parameters
x0start of line 1
y0start of line 1
x1end of line 1
y1end of line 1
x2start of line 2
y2start of line 2
x3end of line 2
y3end of line 2
Returns
true if the lines intersect

◆ line_line_infinite_p() [1/2]

static double[] game2dai.maths.Geometry2D.line_line_infinite_p ( double  x0,
double  y0,
double  x1,
double  y1,
double  x2,
double  y2,
double  x3,
double  y3 
)
static

Find the point of intersection between two infinite lines that pass through the points ([x0,y0],[x1,y1]) and ([x2,y2],[x3,y3]).
An array is returned that contains the intersection points in x, y order. If the array is of length:
0 then there is no intersection
2 these are the x/y coordinates of the intersection point.

Returns
an array of coordinates for the intersection if any

◆ line_line_infinite_p() [2/2]

static Vector2D game2dai.maths.Geometry2D.line_line_infinite_p ( Vector2D  v0,
Vector2D  v1,
Vector2D  v2,
Vector2D  v3 
)
static

Find the intersection point between two infinite lines that pass through the points (v0,v1) and (v2,v3)

Returns
a Vector2D object of the intercept or null if parallel

◆ line_line_p() [1/2]

static double[] game2dai.maths.Geometry2D.line_line_p ( double  x0,
double  y0,
double  x1,
double  y1,
double  x2,
double  y2,
double  x3,
double  y3 
)
static

Find the point of intersection between two lines.
An array is returned that contains the intersection points in x, y order. If the array is of length:
0 then there is no intersection
2 these are the x/y coordinates of the intersection point.

Parameters
x0start of line 1
y0start of line 1
x1end of line 1
y1end of line 1
x2start of line 2
y2start of line 2
x3end of line 2
y3end of line 2
Returns
an array of coordinates for the intersection if any

◆ line_line_p() [2/2]

static Vector2D game2dai.maths.Geometry2D.line_line_p ( Vector2D  v0,
Vector2D  v1,
Vector2D  v2,
Vector2D  v3 
)
static

Find the point of intersection between two lines.
This method uses Vector2D objects to represent the line end points.

Parameters
v0start of line 1
v1end of line 1
v2start of line 2
v3end of line 2
Returns
a Vector2D object holding the intersection coordinates else null if no intersection

◆ line_lines_p()

static double[] game2dai.maths.Geometry2D.line_lines_p ( double  x0,
double  y0,
double  x1,
double  y1,
double[]  xy,
boolean  continuous 
)
static

Calculate the intersection points between a line and a collection of lines.
This will calculate all the intersection points between a given line and the lines formed from the points in the array xy.
If the parameter continuous = true the points form a continuous line so the

line 1 is from xy[0],xy[1] to xy[2],xy[3] and
line 2 is from xy[2],xy[3] to xy[4],xy[5] and so on

and if continuous is false then each set of four array elements form their own line

line 1 is from xy[0],xy[1] to xy[2],xy[3] and
line 2 is from xy[4],xy[5] to xy[6],xy[7] and so on
Parameters
x0x position of the line start
y0y position of the line start
x1x position of the line end
y1y position of the line end
xyarray of x/y coordinates
continuousif true the points makes a continuous line
Returns
an array with all the intersection coordinates

◆ outcode()

static int game2dai.maths.Geometry2D.outcode ( double  pX,
double  pY,
double  rectX,
double  rectY,
double  rectWidth,
double  rectHeight 
)
staticprivate

◆ point_nearest_infinite_line()

static Vector2D game2dai.maths.Geometry2D.point_nearest_infinite_line ( Vector2D  v0,
Vector2D  v1,
Vector2D  p 
)
static

Given a point find the nearest position on an infinite line.

Parameters
v0line start
v1line end
ppoint to consider
Returns
returns null if the line is undefined else the nearest position

◆ point_nearest_line()

static Vector2D game2dai.maths.Geometry2D.point_nearest_line ( Vector2D  v0,
Vector2D  v1,
Vector2D  p 
)
static

Given a point find the nearest position on a finite line.

Parameters
v0line start
v1line end
ppoint to consider
Returns
returns null if the line is undefined or if the nearest point is not on the line

◆ point_to_line_dist()

static void game2dai.maths.Geometry2D.point_to_line_dist ( double  nearness)
static

This sets the distance used to decide whether a point is 'near, a line. This is initially set at 1.0

Parameters
nearnessmust be >0 otherwise it is unchanged

◆ tangents_between_circles()

static double[] game2dai.maths.Geometry2D.tangents_between_circles ( double  cx0,
double  cy0,
double  r0,
double  cx1,
double  cy1,
double  r1 
)
static

Will calculate the contact points for both outer and inner tangents.
There are no tangents if one circle is completely inside the other. If the circles interact only the outer tangents exist. When the circles do not intersect there will be 4 tangents (outer and inner), the array has the outer pair first.

Parameters
cx0x position for the first circle
cy0y position for the first circle
r0radius of the first circle
cx1x position for the second circle
cy1y position for the second circle
r1radius of the second circle
Returns
an array of tangent contact points

◆ tangents_to_circle()

static double[] game2dai.maths.Geometry2D.tangents_to_circle ( double  x,
double  y,
double  cx,
double  cy,
double  r 
)
static

Calculate the tangents from a point.
If the array is of length:
0 then there is no tangent the point is inside the circle
2 there is just one intersection (the point is on the circumference)
4 there are two points.

Parameters
xx position for point of interest
yy position for point of interest
cxcentre of circle x position
cycentre of circle y position
rradius of circle
Returns
an array of the tangent point coordinates

◆ which_side_pn()

static int game2dai.maths.Geometry2D.which_side_pn ( double  x0,
double  y0,
double  nx,
double  ny,
double  px,
double  py 
)
static

Outside is in the same direction of the plane normal.
This version requires a single point on the plane and the normal direction. Useful for an infinite plane or for testing many points against a single plane when the plane normal does not have to be calculated each time.

Parameters
x0x position point of a point on the plane
y0y position point of a point on the plane
nxx value of normal vector
nyy value of normal vector
pxx position of the point to test
pyy position of the point to test
Returns
returns either PLANE_INSIDE, PLANE_OUTSIDE or ON_PLANE

◆ which_side_pp()

static int game2dai.maths.Geometry2D.which_side_pp ( double  x0,
double  y0,
double  x1,
double  y1,
double  px,
double  py 
)
static

Outside is in the same direction of the plane normal.
The first four parameters represent the start and end position for a line segment (finite plane).

Parameters
x0x start of the line
y0y start of the line
x1x end of the line
y1y end of the line
pxx position of the point to test
pyy position of the point to test
Returns
returns either PLANE_INSIDE, PLANE_OUTSIDE or ON_PLANE

The documentation for this class was generated from the following file: