Package org.pepsoft.util
Class MathUtils
java.lang.Object
org.pepsoft.util.MathUtils
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic doubleclamp(double min, double value, double max) static floatclamp(float min, float value, float max) static intclamp(int min, int value, int max) static longclamp(long min, long value, long max) static doubledistanceToLineSegment(int px, int py, int vx, int vy, int wx, int wy) Calculates the shortest distance of a point to a line segment.static doublegetDistance(double dx, double dy, double dz) Calculates the distance between two points in 3D space.static floatgetDistance(float dx, float dy) Calculates the distance between two points in 2D space.static floatgetDistance(float dx, float dy, float dz) Calculates the distance between two points in 3D space.static floatgetDistance(int dx, int dy) Calculates the distance between two points.static floatgetDistance(int dx, int dy, int dz) static floatgetDistance(int x1, int y1, int x2, int y2) Calculates the distance between two points in two dimensional space.static floatgetDistance(int x1, int y1, int z1, int x2, int y2, int z2) Calculates the distance between two points in three dimensional space.static doublemod(double a, double b) Calculates x modulo y.static floatmod(float a, float b) Calculates x modulo y.static intmod(int a, int b) Calculates x modulo y.static intpow(int x, int y) Positive integer powers.static javax.vecmath.Vector3drotateVectorCC(javax.vecmath.Vector3d vector, javax.vecmath.Vector3d axis, double angle) Rotate a vector counterclockwise around an axis.
-
Field Details
-
TWO_PI
public static final double TWO_PI- See Also:
-
-
Method Details
-
pow
public static int pow(int x, int y) Positive integer powers. -
mod
public static float mod(float a, float b) Calculates x modulo y. This is different than the Java remainder operator (%) in that it always returns a positive value.- Parameters:
a- The operand.b- The modulus.- Returns:
- x modulo y
-
mod
public static double mod(double a, double b) Calculates x modulo y. This is different than the Java remainder operator (%) in that it always returns a positive value.- Parameters:
a- The operand.b- The modulus.- Returns:
- x modulo y
-
mod
public static int mod(int a, int b) Calculates x modulo y. This is different than the Java remainder operator (%) in that it always returns a positive value.- Parameters:
a- The operand.b- The modulus.- Returns:
- x modulo y
-
getDistance
public static float getDistance(int x1, int y1, int x2, int y2) Calculates the distance between two points in two dimensional space. Uses a lookup table for distances below 300 for speed.- Parameters:
x1- The X coordinate of the first point.y1- The Y coordinate of the first point.x2- The X coordinate of the second point.y2- The Y coordinate of the second point.- Returns:
- The distance between the two points.
-
getDistance
public static float getDistance(int x1, int y1, int z1, int x2, int y2, int z2) Calculates the distance between two points in three dimensional space. Uses a lookup table for distances below 50 for speed.- Parameters:
x1- The X coordinate of the first point.y1- The Y coordinate of the first point.z1- The Z coordinate of the first point.x2- The X coordinate of the second point.y2- The Y coordinate of the second point.z2- The Z coordinate of the second point.- Returns:
- The distance between the two points.
-
getDistance
public static float getDistance(int dx, int dy) Calculates the distance between two points. Uses a lookup table for distances below 300 for speed.- Parameters:
dx- The difference along the x axis between the two points.dy- The difference along the y axis between the two points.- Returns:
- The distance between the two points.
-
getDistance
public static float getDistance(float dx, float dy) Calculates the distance between two points in 2D space.- Parameters:
dx- The difference along the x axis between the two points.dy- The difference along the y axis between the two points.- Returns:
- The distance between the two points.
-
getDistance
public static float getDistance(float dx, float dy, float dz) Calculates the distance between two points in 3D space.- Parameters:
dx- The difference along the x axis between the two points.dy- The difference along the y axis between the two points.dz- The difference along the z axis between the two points.- Returns:
- The distance between the two points.
-
getDistance
public static double getDistance(double dx, double dy, double dz) Calculates the distance between two points in 3D space.- Parameters:
dx- The difference along the x axis between the two points.dy- The difference along the y axis between the two points.dz- The difference along the z axis between the two points.- Returns:
- The distance between the two points.
-
getDistance
public static float getDistance(int dx, int dy, int dz) -
clamp
public static int clamp(int min, int value, int max) -
clamp
public static long clamp(long min, long value, long max) -
clamp
public static float clamp(float min, float value, float max) -
clamp
public static double clamp(double min, double value, double max) -
rotateVectorCC
public static javax.vecmath.Vector3d rotateVectorCC(javax.vecmath.Vector3d vector, javax.vecmath.Vector3d axis, double angle) Rotate a vector counterclockwise around an axis.- Parameters:
vector- The vector to rotate.axis- The axis around which to rotate it.angle- How many radians to rotate it counterclockwise.- Returns:
- The rotated vector.
-
distanceToLineSegment
public static double distanceToLineSegment(int px, int py, int vx, int vy, int wx, int wy) Calculates the shortest distance of a point to a line segment.- Parameters:
px- The X coordinate of the point.py- The Y coordinate of the point.vx- The X coordinate of the start of the line segment.vy- The Y coordinate of the start of the line segment.wx- The X coordinate of the end of the line segment.wy- The Y coordinate of the end of the line segment.- Returns:
- The shortest distance of the specified point to the specified line segment.
-