@Test public void tangentialIntersections() { ICircle circle = Circle.createCircle(Vector2.fromXY(1000, 500), 300); assertThat(CircleMath.tangentialIntersections(circle, Vector2.fromXY(1000, 500)).get(0) .distanceTo(Vector2.fromXY(1300, 500)) < 1e-3).isTrue(); assertThat(CircleMath.tangentialIntersections(circle, Vector2.fromXY(1000, 500)).get(1) .distanceTo(Vector2.fromXY(1300, 500)) < 1e-3).isTrue(); assertThat(CircleMath.tangentialIntersections(circle, Vector2.fromXY(200, 300)).get(0) .distanceTo(Vector2.fromXY(961.892, 202.43)) < 1e-3).isTrue(); assertThat(CircleMath.tangentialIntersections(circle, Vector2.fromXY(200, 300)).get(1) .distanceTo(Vector2.fromXY(826.343, 744.629)) < 1e-3).isTrue(); assertThat(CircleMath.tangentialIntersections(circle, Vector2.fromXY(1000, -200)).get(0) .distanceTo(Vector2.fromXY(1271.052, 371.429)) < 1e-3).isTrue(); assertThat(CircleMath.tangentialIntersections(circle, Vector2.fromXY(1000, -200)).get(1) .distanceTo(Vector2.fromXY(728.948, 371.429)) < 1e-3).isTrue(); assertThat(CircleMath.tangentialIntersections(circle, Vector2.fromXY(1000, 800)).get(0) .distanceTo(Vector2.fromXY(1000, 800)) < 1e-3).isTrue(); assertThat(CircleMath.tangentialIntersections(circle, Vector2.fromXY(1000, 800)).get(1) .distanceTo(Vector2.fromXY(1000, 800)) < 1e-3).isTrue(); }
public static List<IVector2> tangentialIntersections(final ICircle circle, final IVector2 externalPoint) { IVector2 dir = externalPoint.subtractNew(circle.center()); double d = Math.max(circle.radius(), dir.getLength2()); double alpha = SumatraMath.acos(circle.radius() / d); double beta = dir.getAngle(); List<IVector2> points = new ArrayList<>(2); points.add(Vector2.fromAngleLength(beta + alpha, circle.radius()).add(circle.center())); points.add(Vector2.fromAngleLength(beta - alpha, circle.radius()).add(circle.center())); return points; }
CircleMath { public static List<IVector2> tangentialIntersections(final ICircle circle, final IVector2 externalPoint) { IVector2 dir = externalPoint.subtractNew(circle.center()); double d = Math.max(circle.radius(), dir.getLength2()); double alpha = SumatraMath.acos(circle.radius() / d); double beta = dir.getAngle(); List<IVector2> points = new ArrayList<>(2); points.add(Vector2.fromAngleLength(beta + alpha, circle.radius()).add(circle.center())); points.add(Vector2.fromAngleLength(beta - alpha, circle.radius()).add(circle.center())); return points; } }
CircleMath { public static List<IVector2> tangentialIntersections(final ICircle circle, final IVector2 externalPoint) { IVector2 dir = externalPoint.subtractNew(circle.center()); double d = Math.max(circle.radius(), dir.getLength2()); double alpha = SumatraMath.acos(circle.radius() / d); double beta = dir.getAngle(); List<IVector2> points = new ArrayList<>(2); points.add(Vector2.fromAngleLength(beta + alpha, circle.radius()).add(circle.center())); points.add(Vector2.fromAngleLength(beta - alpha, circle.radius()).add(circle.center())); return points; } @SuppressWarnings("unused") private  CircleMath(); }
CircleMath { public static List<IVector2> tangentialIntersections(final ICircle circle, final IVector2 externalPoint) { IVector2 dir = externalPoint.subtractNew(circle.center()); double d = Math.max(circle.radius(), dir.getLength2()); double alpha = SumatraMath.acos(circle.radius() / d); double beta = dir.getAngle(); List<IVector2> points = new ArrayList<>(2); points.add(Vector2.fromAngleLength(beta + alpha, circle.radius()).add(circle.center())); points.add(Vector2.fromAngleLength(beta - alpha, circle.radius()).add(circle.center())); return points; } @SuppressWarnings("unused") private  CircleMath(); static List<IVector2> tangentialIntersections(final ICircle circle, final IVector2 externalPoint); static List<IVector2> lineIntersections(final ICircular circle, final ILineBase line); static List<IVector2> circleIntersections(final ICircle firstCircle, final ICircle secondCircle); static IVector2 nearestPointOutsideCircle(final ICircular circle, final IVector2 point); static boolean isPointInCircle(ICircular circle, IVector2 point, double margin); static boolean isPointInArc(final IArc arc, final IVector2 point, double margin); static IVector2 nearestPointOutsideArc(final IArc arc, final IVector2 point); static Vector2 stepAlongCircle(final IVector2 current, final IVector2 center, final double angle); }
CircleMath { public static List<IVector2> tangentialIntersections(final ICircle circle, final IVector2 externalPoint) { IVector2 dir = externalPoint.subtractNew(circle.center()); double d = Math.max(circle.radius(), dir.getLength2()); double alpha = SumatraMath.acos(circle.radius() / d); double beta = dir.getAngle(); List<IVector2> points = new ArrayList<>(2); points.add(Vector2.fromAngleLength(beta + alpha, circle.radius()).add(circle.center())); points.add(Vector2.fromAngleLength(beta - alpha, circle.radius()).add(circle.center())); return points; } @SuppressWarnings("unused") private  CircleMath(); static List<IVector2> tangentialIntersections(final ICircle circle, final IVector2 externalPoint); static List<IVector2> lineIntersections(final ICircular circle, final ILineBase line); static List<IVector2> circleIntersections(final ICircle firstCircle, final ICircle secondCircle); static IVector2 nearestPointOutsideCircle(final ICircular circle, final IVector2 point); static boolean isPointInCircle(ICircular circle, IVector2 point, double margin); static boolean isPointInArc(final IArc arc, final IVector2 point, double margin); static IVector2 nearestPointOutsideArc(final IArc arc, final IVector2 point); static Vector2 stepAlongCircle(final IVector2 current, final IVector2 center, final double angle);  }