net.phys2d.raw.shapes
Class Line

java.lang.Object
  extended bynet.phys2d.raw.shapes.AbstractShape
      extended bynet.phys2d.raw.shapes.Line
All Implemented Interfaces:
DynamicShape, Shape

public class Line
extends AbstractShape
implements DynamicShape

Implemenation of a bunch of maths functions to do with lines. Note that lines can't be used as dynamic shapes right now - also collision with the end of a line is undefined.


Field Summary
 
Fields inherited from class net.phys2d.raw.shapes.AbstractShape
bounds
 
Constructor Summary
Line(float x, float y)
          Create a new line based on the origin and a single point
Line(float x, float y, boolean inner, boolean outer)
          Create a new line based on the origin and a single point
Line(float x1, float y1, float x2, float y2)
          Create a new line based on two points
Line(ROVector2f start, ROVector2f end)
          Create a new line based on two points
 
Method Summary
 boolean blocksInnerEdge()
          Check if this line blocks the inner side (for want of a better term)
 boolean blocksOuterEdge()
          Check if this line blocks the outer side (for want of a better term)
 float distance(ROVector2f point)
          Get the shortest distance from a point to this line
 float distanceSquared(ROVector2f point)
          Get the shortest distance squared from a point to this line
 void getClosestPoint(ROVector2f point, Vector2f result)
          Get the closest point on the line to a given point
 float getDX()
          Get the x direction of this line
 float getDY()
          Get the y direction of this line
 ROVector2f getEnd()
          Get the end point of the line
 Line getPositionedLine(ROVector2f displacement, float rotation)
          Get a line starting a x,y and ending offset from the current end point.
 ROVector2f getStart()
          Get the start point of the line
 float getSurfaceFactor()
          Some factor based on the edges length of the shape
 Vector2f[] getVertices(ROVector2f displacement, float rotation)
          Return a translated and rotated line.
 float getX1()
          Get the x coordinate of the start point
 float getX2()
          Get the x coordinate of the end point
 float getY1()
          Get the y coordinate of the start point
 float getY2()
          Get the y coordinate of the end point
 Vector2f intersect(Line other)
          Intersect this line with another
 float length()
          Find the length of the line
 float lengthSquared()
          Find the length of the line squared (cheaper and good for comparisons)
 void move(ROVector2f v)
          Move this line a certain amount
 void set(ROVector2f start, ROVector2f end)
          Configure the line
 void setBlocksInnerEdge(boolean innerEdge)
          Indicate if this line blocks on it's inner edge
 void setBlocksOuterEdge(boolean outerEdge)
          Indicate if this line blocks on it's outer edge
 java.lang.String toString()
           
 
Methods inherited from class net.phys2d.raw.shapes.AbstractShape
getBounds
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface net.phys2d.raw.shapes.Shape
getBounds
 

Constructor Detail

Line

public Line(float x,
            float y,
            boolean inner,
            boolean outer)
Create a new line based on the origin and a single point

Parameters:
x - The end point of the line
y - The end point of the line
inner - True if this line blocks on it's inner edge
outer - True if this line blocks on it's outer edge

Line

public Line(float x,
            float y)
Create a new line based on the origin and a single point

Parameters:
x - The end point of the line
y - The end point of the line

Line

public Line(float x1,
            float y1,
            float x2,
            float y2)
Create a new line based on two points

Parameters:
x1 - The x coordinate of the start point
y1 - The y coordinate of the start point
x2 - The x coordinate of the end point
y2 - The y coordinate of the end point

Line

public Line(ROVector2f start,
            ROVector2f end)
Create a new line based on two points

Parameters:
start - The start point
end - The end point
Method Detail

blocksInnerEdge

public boolean blocksInnerEdge()
Check if this line blocks the inner side (for want of a better term)

Returns:
True if this line blocks the inner side

setBlocksInnerEdge

public void setBlocksInnerEdge(boolean innerEdge)
Indicate if this line blocks on it's inner edge

Parameters:
innerEdge - True if this line blocks on it's inner edge

blocksOuterEdge

public boolean blocksOuterEdge()
Check if this line blocks the outer side (for want of a better term)

Returns:
True if this line blocks the outer side

setBlocksOuterEdge

public void setBlocksOuterEdge(boolean outerEdge)
Indicate if this line blocks on it's outer edge

Parameters:
outerEdge - True if this line blocks on it's outer edge

getStart

public ROVector2f getStart()
Get the start point of the line

Returns:
The start point of the line

getEnd

public ROVector2f getEnd()
Get the end point of the line

Returns:
The end point of the line

length

public float length()
Find the length of the line

Returns:
The the length of the line

lengthSquared

public float lengthSquared()
Find the length of the line squared (cheaper and good for comparisons)

Returns:
The length of the line squared

set

public void set(ROVector2f start,
                ROVector2f end)
Configure the line

Parameters:
start - The start point of the line
end - The end point of the line

getDX

public float getDX()
Get the x direction of this line

Returns:
The x direction of this line

getDY

public float getDY()
Get the y direction of this line

Returns:
The y direction of this line

getX1

public float getX1()
Get the x coordinate of the start point

Returns:
The x coordinate of the start point

getY1

public float getY1()
Get the y coordinate of the start point

Returns:
The y coordinate of the start point

getX2

public float getX2()
Get the x coordinate of the end point

Returns:
The x coordinate of the end point

getY2

public float getY2()
Get the y coordinate of the end point

Returns:
The y coordinate of the end point

distance

public float distance(ROVector2f point)
Get the shortest distance from a point to this line

Parameters:
point - The point from which we want the distance
Returns:
The distance from the line to the point

distanceSquared

public float distanceSquared(ROVector2f point)
Get the shortest distance squared from a point to this line

Parameters:
point - The point from which we want the distance
Returns:
The distance squared from the line to the point

getClosestPoint

public void getClosestPoint(ROVector2f point,
                            Vector2f result)
Get the closest point on the line to a given point

Parameters:
point - The point which we want to project
result - The point on the line closest to the given point

getSurfaceFactor

public float getSurfaceFactor()
Description copied from interface: Shape
Some factor based on the edges length of the shape

Specified by:
getSurfaceFactor in interface Shape
Returns:
The factor result - from the original demo
See Also:
Shape.getSurfaceFactor()

getPositionedLine

public Line getPositionedLine(ROVector2f displacement,
                              float rotation)
Get a line starting a x,y and ending offset from the current end point. Curious huh?

Parameters:
displacement - The displacement of the line
rotation - The rotation of the line in radians
Returns:
The newly created line

getVertices

public Vector2f[] getVertices(ROVector2f displacement,
                              float rotation)
Return a translated and rotated line.

Parameters:
displacement - The displacement of the line
rotation - The rotation of the line in radians
Returns:
The two endpoints of this line

move

public void move(ROVector2f v)
Move this line a certain amount

Parameters:
v - The amount to move the line

toString

public java.lang.String toString()
See Also:
Object.toString()

intersect

public Vector2f intersect(Line other)
Intersect this line with another

Parameters:
other - The other line we should intersect with
Returns:
The intersection point or null if the lines are parallel