org.shapelogic.polygon
Class Calculator2D

java.lang.Object
  extended by org.shapelogic.polygon.Calculator2D

public class Calculator2D
extends java.lang.Object

Calculator for simple 2D. There are a lot of small calculations connected with 2D that should not be thrown in Point and Line classes, but belong in a utility class. I might move more stuff into this.

Author:
Sami Badawi

Constructor Summary
Calculator2D()
           
 
Method Summary
static CLine addLines(CLine line1, CLine line2)
           
static double angleBetweenLines(double firstAngle, double nextAngle)
           
static double crossProduct(IPoint2D inPoint1, IPoint2D inPoint2)
          A sine from the first to the second times the 2 vector lengths Not a real cross product, but the length of the cross product vector
static byte directionBetweenNeighborPoints(IPoint2D startPoint, IPoint2D endPoint)
           
static byte directionDifference(byte direction1, byte direction2)
          Takes to directions between 0 and 7, and gives the direction difference.
static double distanceOfPointToLine(IPoint2D point, CLine line)
          This is signed.
static double dotProduct(IPoint2D inPoint1, IPoint2D inPoint2)
          A cosine to the angle between times the 2 vector lengths.
static IPoint2D hatPoint(IPoint2D inPoint)
          Hat is really a vector operator, I consider a Point a vector here.
static IPoint2D intersectionOfLines(CLine line1, CLine line2)
          Very simple turn the 2 line into a line equation: a * x + b * y = c.
static IPoint2D intersectionOfLinesGeometric(CLine activeLine, CLine projectionLine)
          Deprecated. 
static CLine inverseLine(CLine line)
           
static boolean linesParallel(CLine line1, CLine line2)
           
static byte oppositeDirection(byte direction)
           
static boolean pointIsOnLine(IPoint2D point, CLine line)
           
static CLine pointToLine(IPoint2D point)
           
static IPoint2D projectionOfPointOnLine(IPoint2D point, CLine line)
           
static CLine scaleLineFromStartPoint(CLine line, double length)
           
static IPoint2D spannedPoint(IPoint2D point1, IPoint2D point2, double fraction)
          Find a point on a line spanned by 2 other points.
static IPoint2D unitVector(IPoint2D point)
          What should I do about integer based points that does not have a.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Calculator2D

public Calculator2D()
Method Detail

hatPoint

public static IPoint2D hatPoint(IPoint2D inPoint)
Hat is really a vector operator, I consider a Point a vector here. This is maybe simple enough to be on Point classes


dotProduct

public static double dotProduct(IPoint2D inPoint1,
                                IPoint2D inPoint2)
A cosine to the angle between times the 2 vector lengths.


crossProduct

public static double crossProduct(IPoint2D inPoint1,
                                  IPoint2D inPoint2)
A sine from the first to the second times the 2 vector lengths Not a real cross product, but the length of the cross product vector


distanceOfPointToLine

public static double distanceOfPointToLine(IPoint2D point,
                                           CLine line)
This is signed.


scaleLineFromStartPoint

public static CLine scaleLineFromStartPoint(CLine line,
                                            double length)

pointToLine

public static CLine pointToLine(IPoint2D point)

projectionOfPointOnLine

public static IPoint2D projectionOfPointOnLine(IPoint2D point,
                                               CLine line)

inverseLine

public static CLine inverseLine(CLine line)

addLines

public static CLine addLines(CLine line1,
                             CLine line2)

unitVector

public static IPoint2D unitVector(IPoint2D point)
What should I do about integer based points that does not have a.

Parameters:
point -
Returns:
the point scaled to unit length

linesParallel

public static boolean linesParallel(CLine line1,
                                    CLine line2)

intersectionOfLinesGeometric

@Deprecated
public static IPoint2D intersectionOfLinesGeometric(CLine activeLine,
                                                               CLine projectionLine)
Deprecated. 

This version is complicated and has a bug. Make a projection of the start point of line1 on line2 This passes some tests


intersectionOfLines

public static IPoint2D intersectionOfLines(CLine line1,
                                           CLine line2)
Very simple turn the 2 line into a line equation: a * x + b * y = c. So a and b is just the hat vector. While c is what you get when you put one of the point into this.


pointIsOnLine

public static boolean pointIsOnLine(IPoint2D point,
                                    CLine line)

directionBetweenNeighborPoints

public static byte directionBetweenNeighborPoints(IPoint2D startPoint,
                                                  IPoint2D endPoint)

oppositeDirection

public static byte oppositeDirection(byte direction)

directionDifference

public static byte directionDifference(byte direction1,
                                       byte direction2)
Takes to directions between 0 and 7, and gives the direction difference.

Returns:
should be between -4 and 4

angleBetweenLines

public static double angleBetweenLines(double firstAngle,
                                       double nextAngle)

spannedPoint

public static IPoint2D spannedPoint(IPoint2D point1,
                                    IPoint2D point2,
                                    double fraction)
Find a point on a line spanned by 2 other points. part 0 -> minVal, 1 -> maxVal, 0.5 -> middle point



Copyright © 2008. All Rights Reserved.