com.threerings.math
Class Line

java.lang.Object
  extended by com.threerings.math.Line

public class Line
extends Object

A line consisting of a unit normal and a constant. All points on the line satisfy the equation Ax + By + C = 0, where (A, B) is the line normal and C is the constant.


Field Summary
 float constant
          The line constant.
static Line X_AXIS
          The X axis.
static Line Y_AXIS
          The Y axis.
 
Constructor Summary
Line()
          Creates an empty (invalid) line.
Line(float a, float b, float c)
          Creates a line with the specified parameters.
Line(Line other)
          Copy constructor.
Line(Vector2f normal, float constant)
          Creates a line from the specified normal and constant.
 
Method Summary
 boolean equals(Object other)
           
 Line fromPoints(Vector2f p1, Vector2f p2)
          Sets this line based on the two points provided.
 float getDistance(Ray2D ray)
          Computes the signed distance to this line along the specified ray.
 float getDistance(Vector2f pt)
          Computes and returns the signed distance from the line to the specified point.
 boolean getIntersection(Ray2D ray, Vector2f result)
          Computes the intersection of the supplied ray with this line, placing the result in the given vector (if the ray intersects).
 Vector2f getNormal()
          Returns a reference to the line normal.
 int hashCode()
           
 Line set(float a, float b, float c)
          Sets the parameters of the line.
 Line set(Line other)
          Copies the parameters of another line.
 Line set(Vector2f normal, float constant)
          Sets the parameters of the line.
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

X_AXIS

public static final Line X_AXIS
The X axis.


Y_AXIS

public static final Line Y_AXIS
The Y axis.


constant

public float constant
The line constant.

Constructor Detail

Line

public Line(Vector2f normal,
            float constant)
Creates a line from the specified normal and constant.


Line

public Line(float a,
            float b,
            float c)
Creates a line with the specified parameters.


Line

public Line(Line other)
Copy constructor.


Line

public Line()
Creates an empty (invalid) line.

Method Detail

getNormal

public Vector2f getNormal()
Returns a reference to the line normal.


fromPoints

public Line fromPoints(Vector2f p1,
                       Vector2f p2)
Sets this line based on the two points provided.

Returns:
a reference to the line (for chaining).

set

public Line set(Line other)
Copies the parameters of another line.

Returns:
a reference to this line (for chaining).

set

public Line set(Vector2f normal,
                float constant)
Sets the parameters of the line.

Returns:
a reference to this line (for chaining).

set

public Line set(float a,
                float b,
                float c)
Sets the parameters of the line.

Returns:
a reference to this line (for chaining).

getIntersection

public boolean getIntersection(Ray2D ray,
                               Vector2f result)
Computes the intersection of the supplied ray with this line, placing the result in the given vector (if the ray intersects).

Returns:
true if the ray intersects the line (in which case the result will contain the point of intersection), false if not.

getDistance

public float getDistance(Ray2D ray)
Computes the signed distance to this line along the specified ray.

Returns:
the signed distance, or {Float#NaN} if the ray runs parallel to the line.

getDistance

public float getDistance(Vector2f pt)
Computes and returns the signed distance from the line to the specified point.


hashCode

public int hashCode()
Overrides:
hashCode in class Object

equals

public boolean equals(Object other)
Overrides:
equals in class Object


Copyright © 2011. All Rights Reserved.