/** this will check if the radius needs capping, and return a smaller value if it does */ private static final double getCappedOffset(final Point2D p0, final Point2D p2, final Point2D p4, final double offset) { final double radius = Math.min(p2.sub(p0).getLength(), p2.sub(p4).getLength()) / 2;// it must be half, as there may be another radius on the other side, and they should not cross over. return ((offset > radius) ? radius : offset); }
/** this will check if the radius needs capping, and return a smaller value if it does */ private static final double getCappedOffset(final Point2D p0, final Point2D p2, final Point2D p4, final double offset) { final double radius = Math.min(p2.sub(p0).getLength(), p2.sub(p4).getLength()) / 2;// it must be half, as there may be another radius on the other side, and they should not cross over. return ((offset > radius) ? radius : offset); }
/** this will check if the radius needs capping, and return a smaller value if it does */ private static final double getCappedOffset(final Point2D p0, final Point2D p2, final Point2D p4, final double offset) { final double radius = Math.min(p2.sub(p0).getLength(), p2.sub(p4).getLength()) / 2;// it must be half, as there may be another radius on the other side, and they should not cross over. return ((offset > radius) ? radius : offset); }
/** * Returns the clockwise angle between three points. * It starts at p0, that goes clock-wise around c until it reaches p1 * * @param p0 * @param c * @param p1 * @return */ public static double getClockwiseAngleBetweenThreePoints(final Point2D p0, final Point2D c, final Point2D p1) { final Point2D a = c.sub(p1); final Point2D b = c.sub(p0); return Math.atan2(a.getY(), a.getX()) - Math.atan2(b.getY(), b.getX()); }
/** * Returns the clockwise angle between three points. * It starts at p0, that goes clock-wise around c until it reaches p1 * * @param p0 * @param c * @param p1 * @return */ public static double getClockwiseAngleBetweenThreePoints(final Point2D p0, final Point2D c, final Point2D p1) { final Point2D a = c.sub(p1); final Point2D b = c.sub(p0); return Math.atan2(a.getY(), a.getX()) - Math.atan2(b.getY(), b.getX()); }
/** * Returns the clockwise angle between three points. * It starts at p0, that goes clock-wise around c until it reaches p1 * * @param p0 * @param c * @param p1 * @return */ public static double getClockwiseAngleBetweenThreePoints(final Point2D p0, final Point2D c, final Point2D p1) { final Point2D a = c.sub(p1); final Point2D b = c.sub(p0); return Math.atan2(a.getY(), a.getX()) - Math.atan2(b.getY(), b.getX()); }
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)); } }
/** * 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); }
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; }
@Override public Point2D getAdjust() { if (isEnabled() && (m_intersection != null)) { m_dockPosition = calculateAbsCandidateLocation(getShape(), getCloserMagnet(getShape(), getParent(), false)); return m_dockPosition.sub(m_initialPathLocation); } return new Point2D(0, 0); }
@Override public Point2D getAdjust() { if (isEnabled() && (m_intersection != null)) { m_dockPosition = calculateAbsCandidateLocation(getShape(), getCloserMagnet(getShape(), getParent(), false)); return m_dockPosition.sub(m_initialPathLocation); } return new Point2D(0, 0); }
@Override public Point2D getAdjust() { if (isEnabled() && (m_intersection != null)) { m_dockPosition = calculateAbsCandidateLocation(getShape(), getCloserMagnet(getShape(), getParent(), false)); return m_dockPosition.sub(m_initialPathLocation); } return new Point2D(0, 0); }
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 } }