Package edu.tufts.hrilab.util
Class SimpleGeometry
java.lang.Object
edu.tufts.hrilab.util.SimpleGeometry
Provides static methods for geometry calculations.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic final double
diffAngle
(double a1, double a2) Return the (smallest) difference between two angles (in radians), assumed to have the same origin.static final double
direction
(double a1, double a2) Return a double indicating the direction of one angle relative to another (angles measured in radians and assumed to share origins).static final double
direction
(double x1, double y1, double x2, double y2, double x3, double y3) Return a double indicating the direction of a point relative to a line (as defined by two other points).static final double
Return a double indicating the direction of a point relative to a line.static final double
Return a double indicating the direction of a point relative to a line (as defined by two other points).static final double
lawOfCosDist
(double a, double b, double ca) Given the length of two legs of a triangle and the angle between them, calculates the length of the third leg.static final double
normAngle
(double ang) Normalize an angle.static final double[]
polarToGlobal
(double[] g, double d, double a) Given a global locationg
and a relative polar pointP
, return the global location ofP
as an (x,y) array.static javax.vecmath.Vector3d
projectVectorOntoPlane
(javax.vecmath.Vector3d residual_vector, javax.vecmath.Vector3d plane_normal) Calculates the vector projection onto a plane defined by its normal vector
-
Constructor Details
-
SimpleGeometry
public SimpleGeometry()
-
-
Method Details
-
direction
public static final double direction(double x1, double y1, double x2, double y2, double x3, double y3) Return a double indicating the direction of a point relative to a line (as defined by two other points). This is done by translating the points such that one end of the line is treated as the origin, then finding the cross-product of the other two (modified from Cormen, et al., Intro to Alg's, 2001, p936).- Parameters:
x1
- The x coordinate of point 1 (the line's origin)y1
- The y coordinate of point 1 (the line's origin)x2
- The x coordinate of point 2 (the line's endpoint)y2
- The y coordinate of point 2 (the line's endpoint)x3
- The x coordinate of point 3 (the relative point)y3
- The y coordinate of point 3 (the relative point)- Returns:
- A value that is:
- negative if the point is counter-clockwise to the line
- zero if the point is on the line
- positive if the point is clockwise to the line
-
direction
Return a double indicating the direction of a point relative to a line (as defined by two other points).- Parameters:
p1
- Point 1 (the line's origin)p2
- Point 2 (the line's endpoint)p3
- Point 3 (the relative point)- Returns:
- negative for counter-clockwise, zero for coincident, positive for clockwise
-
direction
Return a double indicating the direction of a point relative to a line.- Parameters:
ln
- The linept
- The relative point- Returns:
- negative for counter-clockwise, zero for coincident, positive for clockwise
-
direction
public static final double direction(double a1, double a2) Return a double indicating the direction of one angle relative to another (angles measured in radians and assumed to share origins). Note that the value returned is the negation of the difference between the angles (in radians).- Parameters:
a1
- The source anglea2
- The target angle- Returns:
- negative for counter-clockwise, zero for coincident, positive for clockwise
-
diffAngle
public static final double diffAngle(double a1, double a2) Return the (smallest) difference between two angles (in radians), assumed to have the same origin.- Parameters:
a1
- An anglea2
- Another angle- Returns:
- An angle ranging from
-PI < angle <= PI
-
normAngle
public static final double normAngle(double ang) Normalize an angle.- Parameters:
ang
- The angle- Returns:
- An angle ranging from
-PI < angle <= PI
-
lawOfCosDist
public static final double lawOfCosDist(double a, double b, double ca) Given the length of two legs of a triangle and the angle between them, calculates the length of the third leg.- Parameters:
a
- The length of one triangle's legb
- The length of another triangle's legca
- The angle betweena
andb
- Returns:
- The length of the triangle's third leg
-
polarToGlobal
public static final double[] polarToGlobal(double[] g, double d, double a) Given a global locationg
and a relative polar pointP
, return the global location ofP
as an (x,y) array.P
is specified in polar representation, (i.e., distance and angle) relative tog
, which is taken as the origin of the line having lengthd
at anglea
.- Parameters:
g
- The global coordinates (x, y, theta), theta in radiansd
-P
's distancea
-P
's angle (in radians)- Returns:
- An (x,y) array representing
P
's global coordinates
-
projectVectorOntoPlane
public static javax.vecmath.Vector3d projectVectorOntoPlane(javax.vecmath.Vector3d residual_vector, javax.vecmath.Vector3d plane_normal) Calculates the vector projection onto a plane defined by its normal vector- Parameters:
residual_vector
- The vector that lies outside the projection/planeplane_normal
- The vector that is normal to the plane being projected onto- Returns:
- The projection vector from the residual_vector onto the plane
-