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 distanceFromLine(VectorXZ p, VectorXZ v1, VectorXZ v2)
          returns the closest distance between point p and a line defined by two points
static double distanceFromLineSegment(VectorXZ p, LineSegmentXZ s)
          returns the closest distance between point p and line segment s
static List<VectorXZ> distributePointsOn(long seed, PolygonWithHolesXZ polygonWithHolesXZ, AxisAlignedBoundingBoxXZ boundary, double density, double minimumDistance)
          distributes points pseudo-randomly on a polygon area.
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 PolygonXZ insertIntoPolygon(PolygonXZ polygon, VectorXZ point, double snapDistance)
          returns a polygon that is constructed from a given polygon by inserting a point into one of the segments of the original polygon.
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.
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<VectorXYZ> sequenceAbove(List<VectorXYZ> sequence, double yDistance)
          returns a sequence of vectors at a distance above an original sequence
static
<V> List<V>
triangleNormalListFromTriangleStrip(List<? extends V> normals)
           
static List<TriangleXYZ> trianglesFromTriangleFan(List<? extends VectorXYZ> vs)
           
static List<TriangleXYZ> trianglesFromTriangleStrip(List<? extends VectorXYZ> vs)
           
static List<TriangleXYZ> trianglesFromVertexList(List<? extends VectorXYZ> vs)
           
static
<V> List<V>
triangleVertexListFromTriangleFan(List<? extends V> vs)
           
static
<V> List<V>
triangleVertexListFromTriangleStrip(List<? extends V> 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)

triangleVertexListFromTriangleStrip

public static final <V> List<V> triangleVertexListFromTriangleStrip(List<? extends V> vs)

triangleNormalListFromTriangleStrip

public static final <V> List<V> triangleNormalListFromTriangleStrip(List<? extends V> normals)

trianglesFromTriangleFan

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

triangleVertexListFromTriangleFan

public static final <V> List<V> triangleVertexListFromTriangleFan(List<? extends V> 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.


distanceFromLine

public static final double distanceFromLine(VectorXZ p,
                                            VectorXZ v1,
                                            VectorXZ v2)
returns the closest distance between point p and a line defined by two points


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

insertIntoPolygon

public static PolygonXZ insertIntoPolygon(PolygonXZ polygon,
                                          VectorXZ point,
                                          double snapDistance)
returns a polygon that is constructed from a given polygon by inserting a point into one of the segments of the original polygon. The segment chosen for this purpose is the one closest to the new node.

Parameters:
polygon - original polygon, will not be modified by this method
point - the new point
snapDistance - minimum distance of new point from segment endpoints; if the new point is closer, the unmodified original polygon will be returned.

distributePointsOn

public static List<VectorXZ> distributePointsOn(long seed,
                                                PolygonWithHolesXZ polygonWithHolesXZ,
                                                AxisAlignedBoundingBoxXZ boundary,
                                                double density,
                                                double minimumDistance)
distributes points pseudo-randomly on a polygon area. The distribution for a set of parameters will always be identical. This can be used for features such as trees in a forest. Distribution works by slicing the area's bounding box into smaller boxes with POINTS_PER_BOX potential points each, the size of these boxes depending on density. In each of the boxes, POINTS_PER_BOX pseudo-random positions will be calculated. If a position is far enough from previous ones and not inside a hole, the position will be contained in the result.

Parameters:
seed - a seed for random number generation
polygonWithHolesXZ - polygon on which the points should be placed
boundary - boundary of the relevant area or null; points outside of the boundary are optional.
density - desired number of points per unit of area
minimumDistance - minimum distance between resulting points (not yet implemented)