Into

Modules

Documentation

namespace referencePiiGeometry

Definitions for geometrical calculations and different algorithms for handling geometric objects.

Functions

template<class T>
T
( )

Calculate the shortest distance between two 3D lines.

template<class T>
T
( )

Point distance from a line segment.

template<class T>
void
(
  • const PiiMatrix< T > & vertices
  • double tolerance
  • int start
  • int end
  • PiiMatrix< T > & result
)

Douglas-Peucker recursive polyline simplification algorithm.

template<class T>
PiiMatrix< T >
(
  • const PiiMatrix< T > & vertices
  • double tolerance
)

Simplify a polyline.

Function details

  • template<class T>

    T lineToLineDistance

    ( )

    #include <PiiGeometry.h>

    Calculate the shortest distance between two 3D lines.

     // Two 3D lines.
     PiiMatrix<double> first(2, 3,
                             0.0, 0.0, 0.0,
                             0.0, 2.0, 0.0);
     PiiMatrix<double> second(1, 6,
                              4.0, 0.0, 0.0,
                              4.0, 0.0, 4.0);
    
     double distance = PiiGeometry::lineToLineDistance(first, second);
    
     // distance is now 4.0
    
    Parameters
    first

    a 2-by-3 matrix whose first row is the direction of the line and the second row any point on the line.

    second

    a 2-by-3 matrix whose first row is the direction of the line and the second row any point on the line.

    Returns

    the shortest distance between the two lines

  • template<class T>

    T pointToLineSegmentDistance

    ( )

    #include <PiiGeometry.h>

    Point distance from a line segment.

    Parameters
    line

    a 2-by-3 (or 2-by-2) matrix which first row contains line segment begin point and second row end point.

    point

    is a 1x3 or 1x2 matrix that represents point which distance from line segment we want to calculate.

    Returns

    point distance from a line segment, if there is anykind problem NAN value will be returned.

  • template<class T>

    void reduceVertices

    (
    • const PiiMatrix< T > & vertices
    • double tolerance
    • int start
    • int end
    • PiiMatrix< T > & result
    )

    #include <PiiGeometry.h>

    Douglas-Peucker recursive polyline simplification algorithm.

    Parameters
    vertices

    the input vertices forming a polyline. Each row in the matrix represents a point in N-dimensional coordinates.

    tolerance

    the maximum allowed deviation between an original data point and a reduced edge. This distance must be squared. If you allow a deviation of 5 (pixels or anything), give 25 as the tolerance.

    start

    the index of the first vertex in the optimization range.

    end

    the index of the last vertex in the optimization range.

    result

    a matrix to which the retained vertices will be stored. The start and end point will not be stored.

  • template<class T>

    PiiMatrix< T > reduceVertices

    (
    • const PiiMatrix< T > & vertices
    • double tolerance
    )

    #include <PiiGeometry.h>

    Simplify a polyline.

    This function uses a two-step algorithm that first prunes all vertices that are within tolerance from each other and then uses the Douglas-Peucker recursive algorithm to further optimize the polyline.

    Parameters
    vertices

    the input vertices forming a polyline. Each row in the matrix represents a point in N-dimensional coordinates.

    tolerance

    the maximum allowed deviation between an original data point and a reduced edge. This distance must be squared. If you allow a deviation of 5 (pixels or anything else), give 25 as the tolerance.

    Returns

    a matrix containing the retained vertices. The first and last point in vertices will always be the last and first points in the result matrix.

Notes (0)

Add a note

Not a single note added yet. Be the first, add yours.