|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.ignotus.geom.GeomUtils
public class GeomUtils
Provides static methods for basic geometric transforms. Methods for translating, scaling, and rotating a point, with single precision (using floats). Rotation and scaling center on (0,0) unless you call scaleCoorAroundPoint or rotateCoorAroundPoint. Rotation is counterclockwise in Cartesian coordinate system (positive y-axis points up) and clockwise in screen display system (positive y-axis points down). Methods that accept separate x and y coordinates return a new Point2D. Methods that accept a Point2D modify and return the point (this allows chaining of methods). It's possible to do all this with matrices, of course, and often (but not always) more efficient.
Field Summary | |
---|---|
static double |
TWO_PI
|
Method Summary | |
---|---|
static double |
area(double[] coords)
outputs area of polygon, negative if vertices are in CCW order. |
static float |
area(float[] coords)
outputs area of polygon, negative if vertices are in CCW order. |
static float |
area(int[] coords)
outputs area of polygon, negative if vertices are in CCW order. |
static double |
clamp(double v,
double l,
double h)
clamps input v to the specified range from l to h |
static float |
clamp(float v,
float l,
float h)
clamps input v to the specified range from l to h |
static double |
distSquared(double x0,
double y0,
double x1,
double y1)
finds squared distance between two points |
static float |
distSquared(float x0,
float y0,
float x1,
float y1)
finds squared distance between two points |
static double |
getAngle(double dx,
double dy)
|
static float |
getAngle(float dx,
float dy)
Given dx and dy displacements on x axis and y axis, returns the angle of rotation, measured counterclockwise from 0 in Cartesian system, in radians. |
static double |
lerp(double a,
double l,
double h)
Interpolates a value within a range. |
static float |
lerp(float a,
float l,
float h)
Interpolates a value within a range. |
static boolean |
pointInPoly(int npol,
double[] xp,
double[] yp,
double x,
double y)
|
static boolean |
pointInPoly(int npol,
float[] xp,
float[] yp,
float x,
float y)
decides if a point is inside a polygon |
static Point2D.Double |
rotateCoor(double x,
double y,
double theta)
|
static Point2D.Float |
rotateCoor(float x,
float y,
float theta)
rotates a point theta radians, returns a new point rotation is counterclockwise for positive theta in Cartesian system, clockwise in screen display coordinate system |
static Point2D.Double |
rotateCoor(Point2D.Double pt,
double theta)
|
static Point2D.Float |
rotateCoor(Point2D.Float pt,
float theta)
rotates a point theta radians, modifies and returns the point rotation is counterclockwise for positive theta in Cartesian system, clockwise in screen display coordinate system |
static Point2D.Double |
rotateCoorAroundPoint(double x,
double y,
double xctr,
double yctr,
double theta)
|
static Point2D.Float |
rotateCoorAroundPoint(float x,
float y,
float xctr,
float yctr,
float theta)
rotates a point theta radians around a point (xctr, yctr), returns a new point rotation is counterclockwise for positive theta in Cartesian system, clockwise in screen display coordinate system |
static Point2D.Double |
rotateCoorAroundPoint(Point2D.Double pt,
double xctr,
double yctr,
double theta)
|
static Point2D.Float |
rotateCoorAroundPoint(Point2D.Float pt,
float xctr,
float yctr,
float theta)
rotates a point theta radians around a point (xctr, yctr), modifies and returns the point rotation is counterclockwise for positive theta in Cartesian system, clockwise in screen display coordinate system |
static Point2D.Double |
scaleCoor(double x,
double y,
double xScale,
double yScale)
|
static Point2D.Float |
scaleCoor(float x,
float y,
float xScale,
float yScale)
scales a point by xScale and yScale, returns a new point |
static Point2D.Double |
scaleCoor(Point2D.Double pt,
double xScale,
double yScale)
|
static Point2D.Float |
scaleCoor(Point2D.Float pt,
float xScale,
float yScale)
scales a point by xScale and yScale, modifies and returns the point |
static Point2D.Double |
scaleCoorAroundPoint(double x,
double y,
double xScale,
double yScale,
double xctr,
double yctr)
|
static Point2D.Float |
scaleCoorAroundPoint(float x,
float y,
float xScale,
float yScale,
float xctr,
float yctr)
scales a point by xScale and yScale arround a point (xctr, yctr), returns a new point |
static Point2D.Float |
scaleCoorAroundPoint(Point2D.Float pt,
float xScale,
float yScale,
float xctr,
float yctr)
scales a point by xScale and yScale around a point (xctr, yctr), modifies and returns the point |
static int |
sgn(double a)
take binary sign of a, either -1, or 1 if >= 0 |
static int |
sgn(float a)
take binary sign of a, either -1, or 1 if >= 0 |
static int |
sgn(int a)
take binary sign of a, either -1, or 1 if >= 0 |
static int |
sgn(long a)
take binary sign of a, either -1, or 1 if >= 0 |
static Point2D.Double |
translateCoor(double x,
double y,
double xOffset,
double yOffset)
|
static Point2D.Float |
translateCoor(float x,
float y,
float xOffset,
float yOffset)
translates a point by xOffset and yOffset, returns a new point |
static Point2D.Double |
translateCoor(Point2D.Double pt,
double xOffset,
double yOffset)
|
static Point2D.Float |
translateCoor(Point2D.Float pt,
float xOffset,
float yOffset)
translates a point by xOffset and yOffset, modifies and returns the point |
static double[] |
xCoords(double[] arr)
|
static float[] |
xCoords(float[] arr)
extracts array of x-coordinates from an array of points in x,y order |
static double[] |
yCoords(double[] arr)
|
static float[] |
yCoords(float[] arr)
extracts array of y-coordinates from an array of points in x,y order |
static int |
zsgn(double a)
take sign of a, either -1, 0, or 1 |
static int |
zsgn(float a)
take sign of a, either -1, 0, or 1 |
static int |
zsgn(int a)
take sign of a, either -1, 0, or 1 |
static int |
zsgn(long a)
take sign of a, either -1, 0, or 1 |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final double TWO_PI
Method Detail |
---|
public static int zsgn(double a)
public static int zsgn(float a)
public static int zsgn(int a)
public static int zsgn(long a)
public static int sgn(double a)
public static int sgn(float a)
public static int sgn(int a)
public static int sgn(long a)
public static double lerp(double a, double l, double h)
public static float lerp(float a, float l, float h)
public static double clamp(double v, double l, double h)
public static float clamp(float v, float l, float h)
public static Point2D.Float scaleCoor(float x, float y, float xScale, float yScale)
x
- x coordinate of pointy
- y coordinate of pointxScale
- scaling on x-axisyScale
- scaling on y-axis
public static Point2D.Double scaleCoor(double x, double y, double xScale, double yScale)
public static Point2D.Float scaleCoor(Point2D.Float pt, float xScale, float yScale)
pt
- the point to scalexScale
- scaling on x-axisyScale
- scaling on y-axis
public static Point2D.Double scaleCoor(Point2D.Double pt, double xScale, double yScale)
public static Point2D.Float scaleCoorAroundPoint(float x, float y, float xScale, float yScale, float xctr, float yctr)
x
- x coordinate of pointy
- y coordinate of pointxScale
- scaling on x-axisyScale
- scaling on y-axisxctr
- x coordinate of center of transformationyctr
- y coordinate of center of transformation
public static Point2D.Double scaleCoorAroundPoint(double x, double y, double xScale, double yScale, double xctr, double yctr)
public static Point2D.Float scaleCoorAroundPoint(Point2D.Float pt, float xScale, float yScale, float xctr, float yctr)
pt
- the point to scalexScale
- scaling on x-axisyScale
- scaling on y-axisxctr
- x coordinate of center of transformationyctr
- y coordinate of center of transformation
public static Point2D.Float translateCoor(float x, float y, float xOffset, float yOffset)
x
- x coordinate of pointy
- y coordinate of pointxOffset
- distance to translate on x-xisyOffset
- distance to translate on y-axis
public static Point2D.Double translateCoor(double x, double y, double xOffset, double yOffset)
public static Point2D.Float translateCoor(Point2D.Float pt, float xOffset, float yOffset)
pt
- the point to translatexOffset
- distance to translate on x-xisyOffset
- distance to translate on y-axis
public static Point2D.Double translateCoor(Point2D.Double pt, double xOffset, double yOffset)
public static Point2D.Float rotateCoor(float x, float y, float theta)
x
- x coordinate of pointy
- y coordinate of pointtheta
- angle to rotate, in radians
public static Point2D.Double rotateCoor(double x, double y, double theta)
public static Point2D.Float rotateCoor(Point2D.Float pt, float theta)
pt
- the point to rotatetheta
- angle to rotate, in radians
public static Point2D.Double rotateCoor(Point2D.Double pt, double theta)
public static Point2D.Float rotateCoorAroundPoint(float x, float y, float xctr, float yctr, float theta)
x
- x coordinate of pointy
- y coordinate of pointxctr
- x coordinate of center of rotationyctr
- y coordinate of center of rotationtheta
- angle to rotate, in radians
public static Point2D.Double rotateCoorAroundPoint(double x, double y, double xctr, double yctr, double theta)
public static Point2D.Float rotateCoorAroundPoint(Point2D.Float pt, float xctr, float yctr, float theta)
pt
- the point to rotatexctr
- x coordinate of center of rotationyctr
- y coordinate of center of rotationtheta
- angle to rotate, in radians
public static Point2D.Double rotateCoorAroundPoint(Point2D.Double pt, double xctr, double yctr, double theta)
public static float getAngle(float dx, float dy)
dx
- x coordinate of pointdy
- y coordinate of point
public static double getAngle(double dx, double dy)
public static boolean pointInPoly(int npol, float[] xp, float[] yp, float x, float y)
npol
- number of points in polygonxp
- array of x-coordinatesyp
- array of y-coordinatesx
- x-coordinate of pointy
- y-coordinate of point
public static boolean pointInPoly(int npol, double[] xp, double[] yp, double x, double y)
public static float[] xCoords(float[] arr)
arr
- array of points in x,y order
public static double[] xCoords(double[] arr)
public static float[] yCoords(float[] arr)
arr
- array of points in x,y order
public static double[] yCoords(double[] arr)
public static float distSquared(float x0, float y0, float x1, float y1)
x0
- x-coordinate of first pointy0
- y-coordinate of first pointx1
- x-coordinate of second pointy1
- y-coordinate of second point
public static double distSquared(double x0, double y0, double x1, double y1)
x0
- x-coordinate of first pointy0
- y-coordinate of first pointx1
- x-coordinate of second pointy1
- y-coordinate of second point
public static float area(int[] coords)
public static float area(float[] coords)
public static double area(double[] coords)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |