Java Geometry Algorithm perpendicular(Point a, Point z, double aDist, double size, boolean clockwise)

Here you can find the source of perpendicular(Point a, Point z, double aDist, double size, boolean clockwise)

Description

Calculates a perpendicular line to a given line.

License

Open Source License

Parameter

Parameter Description
a start of the line
z end of the line
aDist distance from start point of the base line to start point of the perpendicular
size length of the perpendicular
clockwise should it be placed clockwise or counter-clockwise relative to the base line

Declaration

public static Point[] perpendicular(Point a, Point z, double aDist, double size, boolean clockwise) 

Method Source Code


//package com.java2s;
import java.awt.Point;

public class Main {
    /**//from w w  w.  java 2  s . c o m
     * Calculates a perpendicular line to a given line.
     * 
     * @param a start of the line
     * @param z end of the line
     * @param aDist distance from start point of the base line
     * to start point of the perpendicular
     * @param size length of the perpendicular
     * @param clockwise should it be placed clockwise or counter-clockwise
     * relative to the base line
     * @return
     */
    public static Point[] perpendicular(Point a, Point z, double aDist, double size, boolean clockwise) {
        double x = z.x - a.x, y = z.y - a.y;
        double lineLength = Math.hypot(x, y);
        double dx = x / lineLength, dy = y / lineLength;
        double x1 = a.x + dx * aDist, y1 = a.y + dy * aDist;
        if (!clockwise) {
            dx *= -1;
            dy *= -1;
        }

        double x2 = x1 + dy * size, y2 = y1 - dx * size;
        Point p1 = new Point((int) x1, (int) y1);
        Point p2 = new Point((int) x2, (int) y2);
        return new Point[] { p1, p2 };
    }
}

Related

  1. nearestPointOnLine(Line2D l, Point2D p, boolean clampToSegment, Point2D dest)
  2. newZeroPoint()
  3. oneThirdPoint(@Nonnull Point2D pA, @Nonnull Point2D pB)
  4. parabolaByFocusAndDirectrix(Point2D.Double focus, double directrix)
  5. parameterizeCurve(Point[] coefficients, Point startPoint, Point endPoint, Point controlPoint1, Point controlPoint2)
  6. perpendicularScalarProjection(Point2D.Double projVec, Point2D.Double dir)
  7. plotBezier(GeneralPath path, @Nonnull Point2D p0, @Nonnull Point2D p1, @Nonnull Point2D p2, @Nonnull Point2D p3, int depth, double displacement)
  8. plus(Point point1, Point point2)
  9. polarPointAtInfinity(double angle)