Module simpa.core

Class PathUtils

java.lang.Object
simpa.core.api.utils.PathUtils

public class PathUtils extends Object
Utilities for searching on a path (orbit).
  • Method Summary

    Modifier and Type
    Method
    Description
    static double
    calculatePathLength(List<org.apache.commons.math3.geometry.euclidean.threed.Vector3D> path, boolean closed)
    Calculate the sum of the lengths of segments in the path by summing the arc lengths of the segments.
    static List<org.apache.commons.math3.geometry.euclidean.threed.Vector3D>
    createBendingPath(double deflectionAngle, double bendRadius, int nSegments, double extentionLength, boolean sectorBend)
    Create a path for a bending element with the given deflection angle, bend radius, extension lengths at both ends.
    static List<org.apache.commons.math3.geometry.euclidean.threed.Vector3D>
    createStraightLine(org.apache.commons.math3.geometry.euclidean.threed.Vector3D start, org.apache.commons.math3.geometry.euclidean.threed.Vector3D end, int steps)
    Creates a straight part between two locations with points equal to the amount of given steps.
    static void
    extendPath(List<org.apache.commons.math3.geometry.euclidean.threed.Vector3D> path, double distance, boolean atTheEnd)
    Extends the given path at the beginning or at the end by adding a point at the given distance to the path in the direction of the first or last vector in the path.
    static List<org.apache.commons.math3.geometry.euclidean.threed.Vector3D>
    extendWithMirrorOnXAxis(List<org.apache.commons.math3.geometry.euclidean.threed.Vector3D> path)
    Mirrors the path on the X axis by adding the negative of the coordinate designated by the coordinateIndex parameter.
    static List<org.apache.commons.math3.geometry.euclidean.threed.Vector3D>
    extendWithMirrorOnYAxis(List<org.apache.commons.math3.geometry.euclidean.threed.Vector3D> path)
    Mirrors the path on the Y axis by adding the negative of the coordinate designated by the coordinateIndex parameter.
    static List<org.apache.commons.math3.geometry.euclidean.threed.Vector3D>
    extendWithMirrorOnZAxis(List<org.apache.commons.math3.geometry.euclidean.threed.Vector3D> path)
    Mirrors the path on the Z axis by adding the negative of the coordinate designated by the coordinateIndex parameter.
    static List<org.apache.commons.math3.geometry.euclidean.threed.Vector3D>
    getArc(double r, double deflection, int n)
    Calculates a circular arc in the X, Z plane.
    getArcDistances(List<org.apache.commons.math3.geometry.euclidean.threed.Vector3D> path, boolean closed)
    Gets the distances of points along the path from the beginning by summing up the arc-lengths of the segments between the points.
    static int
    getClosestIndex(List<org.apache.commons.math3.geometry.euclidean.threed.Vector3D> path, double longiPos, boolean closedPath)
    This method takes a list of Vector3D points which form a 3D path and returns the index of the point which is closest to the given longitudinal position counted from the first point in the path.
    static int
    getClosestIndex(List<org.apache.commons.math3.geometry.euclidean.threed.Vector3D> path, org.apache.commons.math3.geometry.euclidean.threed.Vector3D point)
    Search the point in the path closest to the given points.
    static double
    getDistance(int from, int to, List<org.apache.commons.math3.geometry.euclidean.threed.Vector3D> path)
    Gets the distance between two points along the path by summing the line segments between the given indices.
    getTangentVector(List<org.apache.commons.math3.geometry.euclidean.threed.Vector3D> path, boolean closed, int index)
    This method takes a list of Vector3D points which form a 3D path and calculates the normalized tangent vector along the path at the given index.
    static boolean
    hasPoint(List<org.apache.commons.math3.geometry.euclidean.threed.Vector3D> path, org.apache.commons.math3.geometry.euclidean.threed.Vector3D point, double tolerance)
    Check if the path contains the given point within the given tolerance.
    static List<org.apache.commons.math3.geometry.euclidean.threed.Vector3D>
    reSamplePath(List<org.apache.commons.math3.geometry.euclidean.threed.Vector3D> path, List<Double> distances)
    Re-samples the given path.
    static List<org.apache.commons.math3.geometry.euclidean.threed.Vector3D>
    transform(List<org.apache.commons.math3.geometry.euclidean.threed.Vector3D> path, org.apache.commons.math3.geometry.euclidean.threed.Rotation rot, org.apache.commons.math3.geometry.euclidean.threed.Vector3D translation)
    Applies the rotation, then the translation to the given path.
    static List<org.apache.commons.math3.geometry.euclidean.threed.Vector3D>
    upSamplePath(List<org.apache.commons.math3.geometry.euclidean.threed.Vector3D> path, double stepSize)
    Up-samples the given path.

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • extendWithMirrorOnXAxis

      public static List<org.apache.commons.math3.geometry.euclidean.threed.Vector3D> extendWithMirrorOnXAxis(List<org.apache.commons.math3.geometry.euclidean.threed.Vector3D> path)
      Mirrors the path on the X axis by adding the negative of the coordinate designated by the coordinateIndex parameter.
      Parameters:
      path - path to extend
      Returns:
      mirrored path
    • extendWithMirrorOnYAxis

      public static List<org.apache.commons.math3.geometry.euclidean.threed.Vector3D> extendWithMirrorOnYAxis(List<org.apache.commons.math3.geometry.euclidean.threed.Vector3D> path)
      Mirrors the path on the Y axis by adding the negative of the coordinate designated by the coordinateIndex parameter.
      Parameters:
      path - path to extend
      Returns:
      mirrored path
    • extendWithMirrorOnZAxis

      public static List<org.apache.commons.math3.geometry.euclidean.threed.Vector3D> extendWithMirrorOnZAxis(List<org.apache.commons.math3.geometry.euclidean.threed.Vector3D> path)
      Mirrors the path on the Z axis by adding the negative of the coordinate designated by the coordinateIndex parameter.
      Parameters:
      path - path to extend
      Returns:
      mirrored path
    • createStraightLine

      public static List<org.apache.commons.math3.geometry.euclidean.threed.Vector3D> createStraightLine(org.apache.commons.math3.geometry.euclidean.threed.Vector3D start, org.apache.commons.math3.geometry.euclidean.threed.Vector3D end, int steps)
      Creates a straight part between two locations with points equal to the amount of given steps.
      Parameters:
      start - start location
      end - end location
      steps - amount of points
      Returns:
      a list of all the points created
    • reSamplePath

      public static List<org.apache.commons.math3.geometry.euclidean.threed.Vector3D> reSamplePath(List<org.apache.commons.math3.geometry.euclidean.threed.Vector3D> path, List<Double> distances)
      Re-samples the given path. The points are taken from the path at the given distances from the first point of the path. Any point of re-sampled path will coincide one of the path points, so the distances are only approximately respected.
      Parameters:
      path - The path to re-sample.
      distances - A list of distances from the first point of the path.
      Returns:
      The re-sampled path.
    • upSamplePath

      public static List<org.apache.commons.math3.geometry.euclidean.threed.Vector3D> upSamplePath(List<org.apache.commons.math3.geometry.euclidean.threed.Vector3D> path, double stepSize)
      Up-samples the given path. The step size should not be bigger than any of the segments in the path.
      Parameters:
      path - The path to up-sample
      stepSize - Step size for the up-sampling.
      Returns:
      The up-sampled path.
    • hasPoint

      public static boolean hasPoint(List<org.apache.commons.math3.geometry.euclidean.threed.Vector3D> path, org.apache.commons.math3.geometry.euclidean.threed.Vector3D point, double tolerance)
      Check if the path contains the given point within the given tolerance.
      Parameters:
      path - The path to be checked.
      point - The point tp be checked against.
      tolerance - The tolerance.
      Returns:
      True if any point in the path is closer to the point than the tolerance distance. False otherwise.
    • getTangentVector

      public static TangentVector3D getTangentVector(List<org.apache.commons.math3.geometry.euclidean.threed.Vector3D> path, boolean closed, int index)
      This method takes a list of Vector3D points which form a 3D path and calculates the normalized tangent vector along the path at the given index. If the closed flag is set to true, the path is treated as a closed loop and the tangent vector is calculated accordingly. If the closed flag is set to false, the tangent vector is calculated as if the path is open and the first and last points are not connected. The tangent vector is calculated by the second order finite difference method.
      Parameters:
      path - The list of Vector3D points which form the path
      closed - A flag indicating whether the path is closed or not
      index - The index of the point along the path for which the tangent vector is to be calculated
      Returns:
      The unit tangent vector at the given index
    • getClosestIndex

      public static int getClosestIndex(List<org.apache.commons.math3.geometry.euclidean.threed.Vector3D> path, org.apache.commons.math3.geometry.euclidean.threed.Vector3D point)
      Search the point in the path closest to the given points.
      Parameters:
      path - The path
      point - The point
      Returns:
      The index of the closest point on the path.
    • getClosestIndex

      public static int getClosestIndex(List<org.apache.commons.math3.geometry.euclidean.threed.Vector3D> path, double longiPos, boolean closedPath)
      This method takes a list of Vector3D points which form a 3D path and returns the index of the point which is closest to the given longitudinal position counted from the first point in the path. If the closed flag is set to true, the path is treated as a closed loop and the closest point is calculated accordingly.
      Parameters:
      path - The path
      longiPos - The longitudinal position at which the closest point is calculated.
      closedPath - Should be set to true if the path forms a closed loop. If true, the line segment formed by the first point and the last point in the path also considered as a segment of the path.
      Returns:
      The index of the closest point.
    • getArcDistances

      public static Map<Integer,Double> getArcDistances(List<org.apache.commons.math3.geometry.euclidean.threed.Vector3D> path, boolean closed)
      Gets the distances of points along the path from the beginning by summing up the arc-lengths of the segments between the points. The arc-length of a segment is calculated from the radius of the circle passing through 3 points. The first and last segments are calculated from the first 3 points and the last 3 points respectively. The intermediate segments are calculated from the previous, current and next points.
      Parameters:
      path - The path to be calculated.
      closed - If true, the path is treated as a closed loop. An arritional point will be added at the end of the path to close the loop.
      Returns:
      A map contaiining the distances of path points from the beginning of the path.
    • getDistance

      public static double getDistance(int from, int to, List<org.apache.commons.math3.geometry.euclidean.threed.Vector3D> path)
      Gets the distance between two points along the path by summing the line segments between the given indices.
      Parameters:
      from - start index
      to - end index
      path - the path to traverse
      Returns:
      the distance between the points
    • extendPath

      public static void extendPath(List<org.apache.commons.math3.geometry.euclidean.threed.Vector3D> path, double distance, boolean atTheEnd)
      Extends the given path at the beginning or at the end by adding a point at the given distance to the path in the direction of the first or last vector in the path.
      Parameters:
      path - The path to be extended.
      distance - The distance of the extension point from the beginning or from the end in the same units the path has (can be any unit).
      atTheEnd - If true, the point will be added at the end , otherwise at the beginning.
    • getArc

      public static List<org.apache.commons.math3.geometry.euclidean.threed.Vector3D> getArc(double r, double deflection, int n)
      Calculates a circular arc in the X, Z plane. X points left with positive bending angle and Y points up. This corresponds to right handed coordinate system.
      Parameters:
      r - Radius of the circle
      deflection - Total angle of the arc [radians]
      n - Number of points in the arc.
      Returns:
      List or arc points.
    • transform

      public static List<org.apache.commons.math3.geometry.euclidean.threed.Vector3D> transform(List<org.apache.commons.math3.geometry.euclidean.threed.Vector3D> path, org.apache.commons.math3.geometry.euclidean.threed.Rotation rot, org.apache.commons.math3.geometry.euclidean.threed.Vector3D translation)
      Applies the rotation, then the translation to the given path.
      Parameters:
      path - A list of points to be transformed.
      rot - A rotation to be applied first.
      translation - A Translation to be applied after the rotation.
      Returns:
      The transformed list of points.
    • createBendingPath

      public static List<org.apache.commons.math3.geometry.euclidean.threed.Vector3D> createBendingPath(double deflectionAngle, double bendRadius, int nSegments, double extentionLength, boolean sectorBend)
      Create a path for a bending element with the given deflection angle, bend radius, extension lengths at both ends. The path consists of a straight segment at the entry and the exits and an arc. The center point of the arc is the origin.
      Parameters:
      deflectionAngle - The deflection angle of the element. [radian]
      bendRadius - The radius of the bending. [arbitrary length unit]
      nSegments - The the number of line segments in the path. It must be even to assure symmetry.
      extentionLength - The length of the straight parts at both ends. [arbitrary length unit]
      sectorBend - True for a sector bending and false for rectangular bending. For a rectangular bending the entry direction of the beam is the +Z axis. For sector bending the angle between the beam entry direction and the +Z axis is deflection/2.
      Returns:
      a list of points making up the path of the bending.
    • calculatePathLength

      public static double calculatePathLength(List<org.apache.commons.math3.geometry.euclidean.threed.Vector3D> path, boolean closed)
      Calculate the sum of the lengths of segments in the path by summing the arc lengths of the segments. The arc length of a segment is calculated from the radius of the circle passing through 3 points. The first and last segments are calculated from the first 3 points and the last 3 points respectively. The intermediate segments are calculated from the previous, current and next points.
      Parameters:
      path - A list of 3D points.
      closed - If the path is closed, the arc distance between the last point and first will be counted in the length.
      Returns:
      The length of the path.