org.osm2world.core.math
Class GeometryUtil

Object
  extended by GeometryUtil

public final class GeometryUtil
extends Object

utility class for some useful calculations


Method Summary
static double distanceFromLineSegment(VectorXZ p, LineSegmentXZ s)
          returns the closest distance between point p and line segment s
static List<VectorXZ> equallyDistributePointsAlong(double preferredDistance, boolean pointsAtStartAndEnd, List<VectorXZ> points)
          distributes points along a line segment sequence.
static List<VectorXZ> equallyDistributePointsAlong(double preferredDistance, boolean pointsAtStartAndEnd, VectorXZ lineStart, VectorXZ lineEnd)
          distributes points along a line segment.
static VectorXZ getLineIntersection(VectorXZ pointA, VectorXZ directionA, VectorXZ pointB, VectorXZ directionB)
          returns the position vector where two lines intersect.
static VectorXZ getLineSegmentIntersection(VectorXZ pointA1, VectorXZ pointA2, VectorXZ pointB1, VectorXZ pointB2)
          returns the position vector where two line segments intersect.
static VectorXZ getTrueLineSegmentIntersection(VectorXZ pointA1, VectorXZ pointA2, VectorXZ pointB1, VectorXZ pointB2)
          variant of getLineSegmentIntersection(VectorXZ, VectorXZ, VectorXZ, VectorXZ) that also returns null (= does not announce an intersection) if the two segments share an end point
static VectorXYZ interpolateBetween(VectorXYZ pos1, VectorXYZ pos2, double influenceRatioPos2)
          three-dimensional version of interpolateBetween(VectorXZ, VectorXZ, double)
static VectorXZ interpolateBetween(VectorXZ pos1, VectorXZ pos2, double influenceRatioPos2)
          returns a point on a line segment between pos1 and pos2, with parameterized placement between the two end nodes.
static VectorXYZ interpolateElevation(VectorXZ posForEle, VectorXYZ pos1, VectorXYZ pos2)
          performs linear interpolation of elevation information for a position on a line segment
static double interpolateValue(VectorXZ posForValue, VectorXZ pos1, double valueAt1, VectorXZ pos2, double valueAt2)
          performs linear interpolation of any value for a position on a line segment
static boolean isBetween(VectorXZ p, VectorXZ l1, VectorXZ l2)
          returns true if p is "between" l1 and l2, i.e. l1 to l2 is the longest side of the triangle p,l1,l2.
static boolean isRightOf(VectorXZ p, VectorXZ l1, VectorXZ l2)
          returns true if the point p is on the right of the line though l1 and l2
static List<VectorXZ> randomlyDistributePointsOn(PolygonWithHolesXZ polygonWithHolesXZ, double density, double minimumDistance)
          distributes points randomly on a polygon area.
static List<VectorXYZ> sequenceAbove(List<VectorXYZ> sequence, double yDistance)
          returns a sequence of vectors at a distance above an original sequence
static List<TriangleXYZ> trianglesFromTriangleFan(List<? extends VectorXYZ> vs)
           
static List<TriangleXYZ> trianglesFromTriangleStrip(List<? extends VectorXYZ> vs)
           
static List<TriangleXYZ> trianglesFromVertexList(List<? extends VectorXYZ> vs)
           
 
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

trianglesFromVertexList

public static final List<TriangleXYZ> trianglesFromVertexList(List<? extends VectorXYZ> vs)

trianglesFromTriangleStrip

public static final List<TriangleXYZ> trianglesFromTriangleStrip(List<? extends VectorXYZ> vs)

trianglesFromTriangleFan

public static final List<TriangleXYZ> trianglesFromTriangleFan(List<? extends VectorXYZ> vs)

getLineIntersection

public static final VectorXZ getLineIntersection(VectorXZ pointA,
                                                 VectorXZ directionA,
                                                 VectorXZ pointB,
                                                 VectorXZ directionB)
returns the position vector where two lines intersect. The lines are given by a point on the line and a direction vector each. Result is null if the lines are parallel or have more than one common point.


getLineSegmentIntersection

public static final VectorXZ getLineSegmentIntersection(VectorXZ pointA1,
                                                        VectorXZ pointA2,
                                                        VectorXZ pointB1,
                                                        VectorXZ pointB2)
returns the position vector where two line segments intersect. The lines are given by a point on the line and a direction vector each. Result is null if the lines are parallel or have more than one common point.


getTrueLineSegmentIntersection

public static final VectorXZ getTrueLineSegmentIntersection(VectorXZ pointA1,
                                                            VectorXZ pointA2,
                                                            VectorXZ pointB1,
                                                            VectorXZ pointB2)
variant of getLineSegmentIntersection(VectorXZ, VectorXZ, VectorXZ, VectorXZ) that also returns null (= does not announce an intersection) if the two segments share an end point


isRightOf

public static final boolean isRightOf(VectorXZ p,
                                      VectorXZ l1,
                                      VectorXZ l2)
returns true if the point p is on the right of the line though l1 and l2


isBetween

public static final boolean isBetween(VectorXZ p,
                                      VectorXZ l1,
                                      VectorXZ l2)
returns true if p is "between" l1 and l2, i.e. l1 to l2 is the longest side of the triangle p,l1,l2. If all three points are on a line, this means that p is on the line segment between l1 and l2.


distanceFromLineSegment

public static final double distanceFromLineSegment(VectorXZ p,
                                                   LineSegmentXZ s)
returns the closest distance between point p and line segment s


sequenceAbove

public static final List<VectorXYZ> sequenceAbove(List<VectorXYZ> sequence,
                                                  double yDistance)
returns a sequence of vectors at a distance above an original sequence

Parameters:
sequence - original sequence
yDistance - distance in y direction between new and original sequence; can be negative for creating a sequence below the original sequence.

interpolateBetween

public static VectorXZ interpolateBetween(VectorXZ pos1,
                                          VectorXZ pos2,
                                          double influenceRatioPos2)
returns a point on a line segment between pos1 and pos2, with parameterized placement between the two end nodes. For example, a parameter of 0.5 would return the center of the line segment; the interpolated point for a parameter of 0.25 would be 1/4 of the distance between pos1 and pos2 away from pos1.


interpolateBetween

public static VectorXYZ interpolateBetween(VectorXYZ pos1,
                                           VectorXYZ pos2,
                                           double influenceRatioPos2)
three-dimensional version of interpolateBetween(VectorXZ, VectorXZ, double)


interpolateElevation

public static VectorXYZ interpolateElevation(VectorXZ posForEle,
                                             VectorXYZ pos1,
                                             VectorXYZ pos2)
performs linear interpolation of elevation information for a position on a line segment


interpolateValue

public static double interpolateValue(VectorXZ posForValue,
                                      VectorXZ pos1,
                                      double valueAt1,
                                      VectorXZ pos2,
                                      double valueAt2)
performs linear interpolation of any value for a position on a line segment


equallyDistributePointsAlong

public static List<VectorXZ> equallyDistributePointsAlong(double preferredDistance,
                                                          boolean pointsAtStartAndEnd,
                                                          VectorXZ lineStart,
                                                          VectorXZ lineEnd)
distributes points along a line segment. This can be used for many different features, such as steps along a way, street lights along a road or posts along a fence.

Parameters:
preferredDistance - ideal distance between resulting points; this method will try to keep the actual distance as close to this as possible
pointsAtStartAndEnd - if true, there will be a point at lineStart and lineEnd each; if false, the closest points will be half the usual distance away from these

equallyDistributePointsAlong

public static List<VectorXZ> equallyDistributePointsAlong(double preferredDistance,
                                                          boolean pointsAtStartAndEnd,
                                                          List<VectorXZ> points)
distributes points along a line segment sequence. This can be used for many different features, such as steps along a way, street lights along a road or posts along a fence.

Parameters:
preferredDistance - ideal distance between resulting points; this method will try to keep the actual distance as close to this as possible
pointsAtStartAndEnd - if true, there will be a point at lineStart and lineEnd each; if false, the closest points will be half the usual distance away from these

randomlyDistributePointsOn

public static List<VectorXZ> randomlyDistributePointsOn(PolygonWithHolesXZ polygonWithHolesXZ,
                                                        double density,
                                                        double minimumDistance)
distributes points randomly on a polygon area. This can be used for different features, such as trees in a forest. Note that the density isn't guaranteed. After several failed attempts to place a point, the distribution will stop even if the density hasn't been reached.

Parameters:
polygonWithHolesXZ - polygon on which the points should be placed
density - desired number of points per unit of area
minimumDistance - minimum distance between resulting points