Here you can find the source of perpendicular(Point a, Point z, double aDist, double size, boolean clockwise)
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 |
public static Point[] perpendicular(Point a, Point z, double aDist, double size, boolean clockwise)
//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 }; } }