public final class Geometry2D
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
static int |
ON_PLANE |
static int |
PLANE_INSIDE |
static int |
PLANE_OUTSIDE |
Constructor and Description |
---|
Geometry2D() |
Modifier and Type | Method and Description |
---|---|
static double[] |
box_box_p(double ax0,
double ay0,
double ax1,
double ay1,
double bx0,
double by0,
double bx1,
double by1)
If two boxes overlap then the overlap region is another box.
|
static boolean |
box_box(double ax0,
double ay0,
double ax1,
double ay1,
double bx0,
double by0,
double bx1,
double by1)
Determine whether two boxes intersect.
|
static double[] |
circle_circle_p(double cx0,
double cy0,
double r0,
double cx1,
double cy1,
double r1)
Calculate the intersection points between two circles.
|
static boolean |
circle_circle(double cx0,
double cy0,
double r0,
double cx1,
double cy1,
double r1)
Determine if two circles overlap
|
static double |
distance_sq(double x0,
double y0,
double x1,
double y1)
Calculates the squared distance between 2 points
|
static double |
distance(double x0,
double y0,
double x1,
double y1)
Calculates the distance between 2 points
|
static boolean |
is_point_near_infinite_line(Vector2D v0,
Vector2D v1,
Vector2D p)
See if point is near the infinite line.
|
static boolean |
is_point_near_infinite_line(Vector2D v0,
Vector2D v1,
Vector2D p,
Vector2D vp)
See if point is near the infinite line.
|
static boolean |
is_point_near_line(Vector2D v0,
Vector2D v1,
Vector2D p)
See if point is near the finite line.
|
static boolean |
is_point_near_line(Vector2D v0,
Vector2D v1,
Vector2D p,
Vector2D vp)
See if point is near the finite line.
|
static boolean |
isInsidePolygon(Vector2D[] verts,
double x0,
double y0)
See if the given point is inside a polygon defined by the vertices provided.
|
static boolean |
isInsideRectangle_xywh(double x0,
double y0,
double width,
double height,
double pX,
double pY)
See if a point is inside the rectangle defined by top-left and bottom right coordinates
|
static boolean |
isInsideRectangle_xywh(Vector2D v0,
double width,
double height,
Vector2D p)
See if this a is inside the rectangle defined by top-left and bottom right coordinates
|
static boolean |
isInsideRectangle_xyxy(double x0,
double y0,
double x1,
double y1,
double pX,
double pY)
See if a point is inside the rectangle defined by top-left and bottom right coordinates
|
static boolean |
isInsideRectangle_xyxy(Vector2D v0,
Vector2D v1,
Vector2D p)
See if this a is inside the rectangle defined by top-left and bottom right coordinates
|
static boolean |
isInsideTriangle(double aX,
double aY,
double bX,
double bY,
double cX,
double cY,
double pX,
double pY)
Determine if the point pX/pY is inside triangle defined by triangle ABC whose
vertices are given by [ax,ay] [bx,by] [cx,cy]
|
static boolean |
isInsideTriangle(Vector2D a,
Vector2D b,
Vector2D c,
double pX,
double pY)
Determine if the point pX/pY is inside triangle defined by triangle ABC
|
static boolean |
isInsideTriangle(Vector2D a,
Vector2D b,
Vector2D c,
Vector2D p)
Determine if the point (p) is inside triangle defined by triangle ABC
|
static boolean |
line_box_xywh(double lx0,
double ly0,
double lx1,
double ly1,
double rx0,
double ry0,
double rWidth,
double rHeight)
Determine whether a line intersects with a box.
|
static boolean |
line_box_xyxy(double lx0,
double ly0,
double lx1,
double ly1,
double rx0,
double ry0,
double rx1,
double ry1)
Determine whether a line intersects with a box.
|
static double[] |
line_circle_p(double x0,
double y0,
double x1,
double y1,
double cx,
double cy,
double r)
Calculate the points of intersection between a line and a circle.
|
static boolean |
line_circle(double x0,
double y0,
double x1,
double y1,
double cx,
double cy,
double r)
Sees if a line intersects with the circumference of a circle.
|
static double[] |
line_line_infinite_p(double x0,
double y0,
double x1,
double y1,
double x2,
double y2,
double x3,
double y3)
Find the point of intersection between two infinite lines that pass through the points
([x0,y0],[x1,y1]) and ([x2,y2],[x3,y3]).
|
static Vector2D |
line_line_infinite_p(Vector2D v0,
Vector2D v1,
Vector2D v2,
Vector2D v3)
Find the intersection point between two infinite lines that
pass through the points (v0,v1) and (v2,v3)
|
static double[] |
line_line_p(double x0,
double y0,
double x1,
double y1,
double x2,
double y2,
double x3,
double y3)
Find the point of intersection between two lines.
|
static Vector2D |
line_line_p(Vector2D v0,
Vector2D v1,
Vector2D v2,
Vector2D v3)
Find the point of intersection between two lines.
|
static boolean |
line_line(double x0,
double y0,
double x1,
double y1,
double x2,
double y2,
double x3,
double y3)
See if two lines intersect
|
static double[] |
line_lines_p(double x0,
double y0,
double x1,
double y1,
double[] xy,
boolean continuous)
Calculate the intersection points between a line and a collection of lines.
|
static Vector2D |
point_nearest_infinite_line(Vector2D v0,
Vector2D v1,
Vector2D p)
Given a point find the nearest position on an infinite line.
|
static Vector2D |
point_nearest_line(Vector2D v0,
Vector2D v1,
Vector2D p)
Given a point find the nearest position on a finite line.
|
static void |
point_to_line_dist(double nearness)
This sets the distance used to decide whether a point is 'near, a line.
|
static double[] |
tangents_between_circles(double cx0,
double cy0,
double r0,
double cx1,
double cy1,
double r1)
Will calculate the contact points for both outer and inner tangents.
|
static double[] |
tangents_to_circle(double x,
double y,
double cx,
double cy,
double r)
Calculate the tangents from a point.
|
static int |
which_side_pn(double x0,
double y0,
double nx,
double ny,
double px,
double py)
Outside is in the same direction of the plane normal.
|
static int |
which_side_pp(double x0,
double y0,
double x1,
double y1,
double px,
double py)
Outside is in the same direction of the plane normal.
|
public static final int ON_PLANE
public static final int PLANE_INSIDE
public static final int PLANE_OUTSIDE
public static void point_to_line_dist(double nearness)
nearness
- must be >0 otherwise it is unchangedpublic static boolean is_point_near_line(Vector2D v0, Vector2D v1, Vector2D p)
v0
- line startv1
- line endp
- point to considerpublic static boolean is_point_near_line(Vector2D v0, Vector2D v1, Vector2D p, Vector2D vp)
v0
- line startv1
- line endp
- point to considervp
- filled with xy position of the nearest point on finite line (must not be null)public static boolean is_point_near_infinite_line(Vector2D v0, Vector2D v1, Vector2D p)
v0
- line passes through this pointv1
- line passes through this pointp
- point to considerpublic static boolean is_point_near_infinite_line(Vector2D v0, Vector2D v1, Vector2D p, Vector2D vp)
v0
- line passes through this pointv1
- line passes through this pointp
- point to considervp
- filled with xy position of the nearest point on line (must not be null)public static Vector2D point_nearest_line(Vector2D v0, Vector2D v1, Vector2D p)
v0
- line startv1
- line endp
- point to considerpublic static Vector2D point_nearest_infinite_line(Vector2D v0, Vector2D v1, Vector2D p)
v0
- line startv1
- line endp
- point to considerpublic static boolean line_circle(double x0, double y0, double x1, double y1, double cx, double cy, double r)
x0
- y0
- x1
- y1
- cx
- centre of circle x positioncy
- centre of circle y positionr
- radius of circlepublic static double[] line_circle_p(double x0, double y0, double x1, double y1, double cx, double cy, double r)
x0
- start of liney0
- start of linex1
- end of liney1
- end of linecx
- centre of circle x positioncy
- centre of circle y positionr
- radius of circlepublic static boolean line_line(double x0, double y0, double x1, double y1, double x2, double y2, double x3, double y3)
x0
- start of line 1y0
- start of line 1x1
- end of line 1y1
- end of line 1x2
- start of line 2y2
- start of line 2x3
- end of line 2y3
- end of line 2public static Vector2D line_line_p(Vector2D v0, Vector2D v1, Vector2D v2, Vector2D v3)
v0
- start of line 1v1
- end of line 1v2
- start of line 2v3
- end of line 2public static Vector2D line_line_infinite_p(Vector2D v0, Vector2D v1, Vector2D v2, Vector2D v3)
public static double[] line_line_p(double x0, double y0, double x1, double y1, double x2, double y2, double x3, double y3)
x0
- start of line 1y0
- start of line 1x1
- end of line 1y1
- end of line 1x2
- start of line 2y2
- start of line 2x3
- end of line 2y3
- end of line 2public static double[] line_line_infinite_p(double x0, double y0, double x1, double y1, double x2, double y2, double x3, double y3)
public static double[] line_lines_p(double x0, double y0, double x1, double y1, double[] xy, boolean continuous)
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 onand 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
x0
- x position of the line starty0
- y position of the line startx1
- x position of the line endy1
- y position of the line endxy
- array of x/y coordinatescontinuous
- if true the points makes a continuous linepublic static boolean circle_circle(double cx0, double cy0, double r0, double cx1, double cy1, double r1)
cx0
- centre of first circle x positioncy0
- centre of first circle y positionr0
- radius of first circlecx1
- centre of second circle x positioncy1
- centre of second circle y positionr1
- radius of second circlepublic static double[] circle_circle_p(double cx0, double cy0, double r0, double cx1, double cy1, double r1)
cx0
- centre of first circle x positioncy0
- centre of first circle y positionr0
- radius of first circlecx1
- centre of second circle x positioncy1
- centre of second circle y positionr1
- radius of second circlepublic static double[] tangents_to_circle(double x, double y, double cx, double cy, double r)
x
- x position for point of interesty
- y position for point of interestcx
- centre of circle x positioncy
- centre of circle y positionr
- radius of circlepublic static double[] tangents_between_circles(double cx0, double cy0, double r0, double cx1, double cy1, double r1)
cx0
- x position for the first circlecy0
- y position for the first circler0
- radius of the first circlecx1
- x position for the second circlecy1
- y position for the second circler1
- radius of the second circlepublic static int which_side_pp(double x0, double y0, double x1, double y1, double px, double py)
x0
- x start of the liney0
- y start of the linex1
- x end of the liney1
- y end of the linepx
- x position of the point to testpy
- y position of the point to testpublic static int which_side_pn(double x0, double y0, double nx, double ny, double px, double py)
x0
- x position point of a point on the planey0
- y position point of a point on the planenx
- x value of normal vectorny
- y value of normal vectorpx
- x position of the point to testpy
- y position of the point to testpublic static boolean line_box_xyxy(double lx0, double ly0, double lx1, double ly1, double rx0, double ry0, double rx1, double ry1)
lx0
- start of linely0
- start of linelx1
- end of linely1
- end of linerx0
- top-left corner of rectanglery0
- top-left corner of rectanglerx1
- bottom-right corner of rectanglery1
- bottom-right corner of rectanglepublic static boolean line_box_xywh(double lx0, double ly0, double lx1, double ly1, double rx0, double ry0, double rWidth, double rHeight)
lx0
- start of linely0
- start of linelx1
- end of linely1
- end of linerx0
- top-left corner of rectanglery0
- top-left corner of rectanglerWidth
- width of rectanglerHeight
- height of rectanglepublic static boolean box_box(double ax0, double ay0, double ax1, double ay1, double bx0, double by0, double bx1, double by1)
ax0
- top-left corner of rectangle Aay0
- top-left corner of rectangle Aax1
- bottom-right corner of rectangle Aay1
- bottom-right corner of rectangle Abx0
- top-left corner of rectangle Bby0
- top-left corner of rectangle Bbx1
- bottom-right corner of rectangle Bby1
- bottom-right corner of rectangle Bpublic static double[] box_box_p(double ax0, double ay0, double ax1, double ay1, double bx0, double by0, double bx1, double by1)
ax0
- top-left corner of rectangle Aay0
- top-left corner of rectangle Aax1
- bottom-right corner of rectangle Aay1
- bottom-right corner of rectangle Abx0
- top-left corner of rectangle Bby0
- top-left corner of rectangle Bbx1
- bottom-right corner of rectangle Bby1
- bottom-right corner of rectangle Bpublic static boolean isInsideTriangle(double aX, double aY, double bX, double bY, double cX, double cY, double pX, double pY)
public static boolean isInsideTriangle(Vector2D a, Vector2D b, Vector2D c, Vector2D p)
a
- triangle vertex 1b
- triangle vertex 2c
- triangle vertex 3p
- point of interestpublic static boolean isInsideTriangle(Vector2D a, Vector2D b, Vector2D c, double pX, double pY)
a
- triangle vertex 1b
- triangle vertex 2c
- triangle vertex 3pX
- x position for point of interestpY
- y position for point of interestpublic static boolean isInsideRectangle_xyxy(double x0, double y0, double x1, double y1, double pX, double pY)
x0
- top-left corner of rectangley0
- top-left corner of rectanglex1
- bottom-right corner of rectangley1
- bottom-right corner of rectanglepX
- x position of point of interestpY
- y position of point of interestpublic static boolean isInsideRectangle_xyxy(Vector2D v0, Vector2D v1, Vector2D p)
v0
- top-left corner of rectanglev1
- bottom-right corner of rectanglep
- point of interestpublic static boolean isInsideRectangle_xywh(double x0, double y0, double width, double height, double pX, double pY)
x0
- top-left corner of rectangley0
- top-left corner of rectanglewidth
- width of rectangleheight
- height of rectanglepX
- x position of point of interestpY
- y position of point of interestpublic static boolean isInsideRectangle_xywh(Vector2D v0, double width, double height, Vector2D p)
v0
- top-left corner of rectanglewidth
- width of rectangleheight
- height of rectanglep
- point of interestpublic static boolean isInsidePolygon(Vector2D[] verts, double x0, double y0)
verts
- the vertices of the shapex0
- y0
- public static double distance_sq(double x0, double y0, double x1, double y1)
x0
- point 1y0
- point 1x1
- point 2y1
- point 2public static double distance(double x0, double y0, double x1, double y1)
x0
- point 1y0
- point 1x1
- point 2y1
- point 2Processing library AI_for_2D_Games by Peter Lager. (C) 2013