Search in sources :

Example 1 with Line

use of me.wobblyyyy.pathfinder2.geometry.Line in project Pathfinder2 by Wobblyyyy.

the class PathOptimizer method determineLength.

/**
 * Determine the length of a set of points/path.
 *
 * @param path the path to determine the total length of.
 * @return the total length of the path.
 */
public static double determineLength(List<PointXY> path) {
    List<Line> lines = new ArrayList<>(path.size() * 2);
    for (int i = 0; i < path.size() - 1; i++) {
        PointXY current = path.get(i);
        PointXY next = path.get(i + 1);
        Line line = new Line(current, next);
        lines.add(line);
    }
    double length = 0;
    for (Line line : lines) {
        length += Math.abs(line.length());
    }
    return length;
}
Also used : Line(me.wobblyyyy.pathfinder2.geometry.Line) PointXY(me.wobblyyyy.pathfinder2.geometry.PointXY) ArrayList(java.util.ArrayList)

Example 2 with Line

use of me.wobblyyyy.pathfinder2.geometry.Line in project Pathfinder2 by Wobblyyyy.

the class LinearTrajectoryBuilder method rotateLine.

/**
 * Move in a line and rotate to a specified heading.
 *
 * @param distance    the distance from the current point that the new
 *                    point should be drawn at.
 * @param targetAngle the angle the trajectory should attempt to turn to.
 * @param angle       the angle at which the line should be drawn.
 */
public LinearTrajectoryBuilder rotateLine(double distance, Angle targetAngle, Angle angle) {
    PointXYZ next = last.inDirection(distance, angle);
    trajectories.add(new LinearTrajectory(next.withHeading(targetAngle), speed, tolerance, angleTolerance));
    last = next;
    return this;
}
Also used : LinearTrajectory(me.wobblyyyy.pathfinder2.trajectory.LinearTrajectory) PointXYZ(me.wobblyyyy.pathfinder2.geometry.PointXYZ)

Aggregations

ArrayList (java.util.ArrayList)1 Line (me.wobblyyyy.pathfinder2.geometry.Line)1 PointXY (me.wobblyyyy.pathfinder2.geometry.PointXY)1 PointXYZ (me.wobblyyyy.pathfinder2.geometry.PointXYZ)1 LinearTrajectory (me.wobblyyyy.pathfinder2.trajectory.LinearTrajectory)1