public static Point2D getProjection(final Point2D center, final Point2D intersection, final double length) { final Point2D unit = intersection.sub(center).unit(); return center.add(unit.mul(length)); } }
public static Point2D getProjection(final Point2D center, final Point2D intersection, final double length) { final Point2D unit = intersection.sub(center).unit(); return center.add(unit.mul(length)); } }
public static Point2D getProjection(final Point2D center, final Point2D intersection, final double length) { final Point2D unit = intersection.sub(center).unit(); return center.add(unit.mul(length)); } }
public static boolean isPointAnIntersectGiveArcBetweenTwoLines(final Point2D l1a, final Point2D l1b, final Point2D p, final Point2D l2a, final double r) { final Point2D dv = l1b.sub(l1a); final Point2D dx = dv.unit(); final Point2D dy = dx.perpendicular(); final Point2D arcCenter = l1b.add(dy.mul(r)); final double angle = getAngleBetweenTwoLines(l1b, arcCenter, l2a); final double l = getLengthFromASA(angle, r, RADIANS_90); final double l4 = Math.sqrt((l * l) - (r * r)); final Point2D intersection = dx.mul(l4); final boolean interseects = intersection.equals(p); return interseects; }
public static boolean isPointAnIntersectGiveArcBetweenTwoLines(final Point2D l1a, final Point2D l1b, final Point2D p, final Point2D l2a, final double r) { final Point2D dv = l1b.sub(l1a); final Point2D dx = dv.unit(); final Point2D dy = dx.perpendicular(); final Point2D arcCenter = l1b.add(dy.mul(r)); final double angle = getAngleBetweenTwoLines(l1b, arcCenter, l2a); final double l = getLengthFromASA(angle, r, RADIANS_90); final double l4 = Math.sqrt((l * l) - (r * r)); final Point2D intersection = dx.mul(l4); final boolean interseects = intersection.equals(p); return interseects; }
public static boolean isPointAnIntersectGiveArcBetweenTwoLines(final Point2D l1a, final Point2D l1b, final Point2D p, final Point2D l2a, final double r) { final Point2D dv = l1b.sub(l1a); final Point2D dx = dv.unit(); final Point2D dy = dx.perpendicular(); final Point2D arcCenter = l1b.add(dy.mul(r)); final double angle = getAngleBetweenTwoLines(l1b, arcCenter, l2a); final double l = getLengthFromASA(angle, r, RADIANS_90); final double l4 = Math.sqrt((l * l) - (r * r)); final Point2D intersection = dx.mul(l4); final boolean interseects = intersection.equals(p); return interseects; }
/** * Canvas arcTo's have a variable center, as points a, b and c form two lines from the same point at a tangent to the arc's cirlce. * This returns the arcTo arc start, center and end points. * * @param p0 * @param p1 * @param r * @return */ public static final Point2DArray getCanvasArcToPoints(final Point2D p0, final Point2D p1, final Point2D p2, final double r) { // see tangents drawn from same point to a circle // http://www.mathcaptain.com/geometry/tangent-of-a-circle.html final double a0 = getAngleBetweenTwoLines(p0, p1, p2) / 2; final double ln = getLengthFromASA(RADIANS_90 - a0, r, a0); Point2D dv = p1.sub(p0); Point2D dx = dv.unit(); Point2D dl = dx.mul(ln); final Point2D ps = p1.sub(dl);// ps is arc start point dv = p1.sub(p2); dx = dv.unit(); dl = dx.mul(ln); final Point2D pe = p1.sub(dl);// ep is arc end point // this gets the direction as a unit, from p1 to the center final Point2D midPoint = new Point2D((ps.getX() + pe.getX()) / 2, (ps.getY() + pe.getY()) / 2); dx = midPoint.sub(p1).unit(); final Point2D pc = p1.add(dx.mul(distance(r, ln))); return new Point2DArray(ps, pc, pe); }
/** * Canvas arcTo's have a variable center, as points a, b and c form two lines from the same point at a tangent to the arc's cirlce. * This returns the arcTo arc start, center and end points. * * @param p0 * @param p1 * @param r * @return */ public static final Point2DArray getCanvasArcToPoints(final Point2D p0, final Point2D p1, final Point2D p2, final double r) { // see tangents drawn from same point to a circle // http://www.mathcaptain.com/geometry/tangent-of-a-circle.html final double a0 = getAngleBetweenTwoLines(p0, p1, p2) / 2; final double ln = getLengthFromASA(RADIANS_90 - a0, r, a0); Point2D dv = p1.sub(p0); Point2D dx = dv.unit(); Point2D dl = dx.mul(ln); final Point2D ps = p1.sub(dl);// ps is arc start point dv = p1.sub(p2); dx = dv.unit(); dl = dx.mul(ln); final Point2D pe = p1.sub(dl);// ep is arc end point // this gets the direction as a unit, from p1 to the center final Point2D midPoint = new Point2D((ps.getX() + pe.getX()) / 2, (ps.getY() + pe.getY()) / 2); dx = midPoint.sub(p1).unit(); final Point2D pc = p1.add(dx.mul(distance(r, ln))); return new Point2DArray(ps, pc, pe); }
/** * Canvas arcTo's have a variable center, as points a, b and c form two lines from the same point at a tangent to the arc's cirlce. * This returns the arcTo arc start, center and end points. * * @param p0 * @param p1 * @param r * @return */ public static final Point2DArray getCanvasArcToPoints(final Point2D p0, final Point2D p1, final Point2D p2, final double r) { // see tangents drawn from same point to a circle // http://www.mathcaptain.com/geometry/tangent-of-a-circle.html final double a0 = getAngleBetweenTwoLines(p0, p1, p2) / 2; final double ln = getLengthFromASA(RADIANS_90 - a0, r, a0); Point2D dv = p1.sub(p0); Point2D dx = dv.unit(); Point2D dl = dx.mul(ln); final Point2D ps = p1.sub(dl);// ps is arc start point dv = p1.sub(p2); dx = dv.unit(); dl = dx.mul(ln); final Point2D pe = p1.sub(dl);// ep is arc end point // this gets the direction as a unit, from p1 to the center final Point2D midPoint = new Point2D((ps.getX() + pe.getX()) / 2, (ps.getY() + pe.getY()) / 2); dx = midPoint.sub(p1).unit(); final Point2D pc = p1.add(dx.mul(distance(r, ln))); return new Point2DArray(ps, pc, pe); }
private static final Point2D correctEndWithOffset(double offset, final Direction direction, final Point2D p0, final Point2D p1, final boolean reverse) { Point2D target; if (reverse) { target = p1; offset = -offset; } else { target = p0; } switch (direction) { case NORTH: return target.setY(target.getY() - offset); case EAST: return target.setX(target.getX() + offset); case SOUTH: return target.setY(target.getY() + offset); case WEST: return target.setX(target.getX() - offset); case NONE: default: return target.add(p1.sub(p0).unit().mul(offset)); // unit vector in the direction of SE } }
final Point2D e = getEnd();// arr.getPoint(1); final Point2D dv = e.sub(s); final Point2D dx = dv.unit();// unit vector in the direction of SE final Point2D dy = dx.perpendicular();
Point2D dx = dv.unit(); // unit vector in the direction of SE Point2D dy = dx.perpendicular();
final Point2D e = getEnd();// arr.getPoint(1); final Point2D dv = e.sub(s); final Point2D dx = dv.unit();// unit vector in the direction of SE final Point2D dy = dx.perpendicular();
final Point2D e = getEnd();// arr.getPoint(1); final Point2D dv = e.sub(s); final Point2D dx = dv.unit();// unit vector in the direction of SE final Point2D dy = dx.perpendicular();