Class SimpleGeometry

java.lang.Object
edu.tufts.hrilab.util.SimpleGeometry

public final class SimpleGeometry extends Object
Provides static methods for geometry calculations.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static 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 location g and a relative polar point P, return the global location of P 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

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 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:
      1. negative if the point is counter-clockwise to the line
      2. zero if the point is on the line
      3. positive if the point is clockwise to the line
    • direction

      public static final double direction(Point2D p1, Point2D p2, Point2D p3)
      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

      public static final double direction(Line2D ln, Point2D pt)
      Return a double indicating the direction of a point relative to a line.
      Parameters:
      ln - The line
      pt - 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 angle
      a2 - 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 angle
      a2 - Another angle
      Returns:
      An angle ranging from -PI &lt angle &lt= PI
    • normAngle

      public static final double normAngle(double ang)
      Normalize an angle.
      Parameters:
      ang - The angle
      Returns:
      An angle ranging from -PI &lt angle &lt= 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 leg
      b - The length of another triangle's leg
      ca - The angle between a and b
      Returns:
      The length of the triangle's third leg
    • polarToGlobal

      public static final double[] polarToGlobal(double[] g, double d, double a)
      Given a global location g and a relative polar point P, return the global location of P as an (x,y) array. P is specified in polar representation, (i.e., distance and angle) relative to g, which is taken as the origin of the line having length d at angle a.
      Parameters:
      g - The global coordinates (x, y, theta), theta in radians
      d - P's distance
      a - 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/plane
      plane_normal - The vector that is normal to the plane being projected onto
      Returns:
      The projection vector from the residual_vector onto the plane