@Test public void testSignedAngleFromSourceHeadingToTarget() { ILocated2D source = new Tuple2D(1, 1); ILocated2D target1 = new Tuple2D(2, 1); ILocated2D target2 = new Tuple2D(1, 1); assertEquals(CartesianGeometricUtilities.signedAngleFromSourceHeadingToTarget(source, target1, Math.PI / 4), -Math.PI / 4, DOUBLE_THRESHOLD); assertEquals(CartesianGeometricUtilities.signedAngleFromSourceHeadingToTarget(source, target2, Math.PI / 4), 0, DOUBLE_THRESHOLD); }
public static double signedAngleFromSourceHeadingToTarget(ILocated2D source, ILocated2D target, double sourceRads) { if (target == null || target.getPosition() == null || source == null || source.getPosition() == null) { return Math.PI; } Tuple2D sourceToTarget = target.getPosition().sub(source); if (sourceToTarget.isZero()) { return 0; } sourceToTarget = sourceToTarget.normalize(); double angleToTarget = sourceToTarget.angle(); return signedAngleDifference(sourceRads, angleToTarget); }
CartesianGeometricUtilities { public static double signedAngleFromSourceHeadingToTarget(ILocated2D source, ILocated2D target, double sourceRads) { if (target == null || target.getPosition() == null || source == null || source.getPosition() == null) { return Math.PI; } Tuple2D sourceToTarget = target.getPosition().sub(source); if (sourceToTarget.isZero()) { return 0; } sourceToTarget = sourceToTarget.normalize(); double angleToTarget = sourceToTarget.angle(); return signedAngleDifference(sourceRads, angleToTarget); } }
CartesianGeometricUtilities { public static double signedAngleFromSourceHeadingToTarget(ILocated2D source, ILocated2D target, double sourceRads) { if (target == null || target.getPosition() == null || source == null || source.getPosition() == null) { return Math.PI; } Tuple2D sourceToTarget = target.getPosition().sub(source); if (sourceToTarget.isZero()) { return 0; } sourceToTarget = sourceToTarget.normalize(); double angleToTarget = sourceToTarget.angle(); return signedAngleDifference(sourceRads, angleToTarget); }  }
CartesianGeometricUtilities { public static double signedAngleFromSourceHeadingToTarget(ILocated2D source, ILocated2D target, double sourceRads) { if (target == null || target.getPosition() == null || source == null || source.getPosition() == null) { return Math.PI; } Tuple2D sourceToTarget = target.getPosition().sub(source); if (sourceToTarget.isZero()) { return 0; } sourceToTarget = sourceToTarget.normalize(); double angleToTarget = sourceToTarget.angle(); return signedAngleDifference(sourceRads, angleToTarget); }  static Tuple2D centerAndScale(Tuple2D toScale, int width, int height); static Vertex centerAndScale(Vertex toScale, int width, int height, int depth); static double centerAndScale(double toScale, int maxDimension); static Tuple2D Bottom1DCenterAndScale(Tuple2D toScale, int width, int height); static Tuple2D bottomCenterAndScale(Tuple2D toScale, int width, int height); static double bottomScale(double toScale, int maxDimension); static double shortestDistanceToLineSegment(ILocated2D p1, ILocated2D l1, ILocated2D l2); static double shortestDistanceToLineSegment(double x, double y, double x1, double x2, double y1, double y2); static double euclideanDistance(ArrayList<Double> x1, ArrayList<Double> x2); static double[] polarToCartesian(double r, double theta); static double signedAngleFromSourceHeadingToTarget(ILocated2D source, ILocated2D target, double sourceRads); static double signedAngleDifference(ILocated2D v1, ILocated2D v2); static double signedAngleDifference(double rad1, double rad2); static boolean sourceHeadingTowardsTarget(double sourceRadians, ILocated2D source, ILocated2D target,
			double allowance); static boolean onSideOf(ILocated2D source, double sourceRadians, ILocated2D other, boolean right); static double restrictRadians(double rads); }
CartesianGeometricUtilities { public static double signedAngleFromSourceHeadingToTarget(ILocated2D source, ILocated2D target, double sourceRads) { if (target == null || target.getPosition() == null || source == null || source.getPosition() == null) { return Math.PI; } Tuple2D sourceToTarget = target.getPosition().sub(source); if (sourceToTarget.isZero()) { return 0; } sourceToTarget = sourceToTarget.normalize(); double angleToTarget = sourceToTarget.angle(); return signedAngleDifference(sourceRads, angleToTarget); }  static Tuple2D centerAndScale(Tuple2D toScale, int width, int height); static Vertex centerAndScale(Vertex toScale, int width, int height, int depth); static double centerAndScale(double toScale, int maxDimension); static Tuple2D Bottom1DCenterAndScale(Tuple2D toScale, int width, int height); static Tuple2D bottomCenterAndScale(Tuple2D toScale, int width, int height); static double bottomScale(double toScale, int maxDimension); static double shortestDistanceToLineSegment(ILocated2D p1, ILocated2D l1, ILocated2D l2); static double shortestDistanceToLineSegment(double x, double y, double x1, double x2, double y1, double y2); static double euclideanDistance(ArrayList<Double> x1, ArrayList<Double> x2); static double[] polarToCartesian(double r, double theta); static double signedAngleFromSourceHeadingToTarget(ILocated2D source, ILocated2D target, double sourceRads); static double signedAngleDifference(ILocated2D v1, ILocated2D v2); static double signedAngleDifference(double rad1, double rad2); static boolean sourceHeadingTowardsTarget(double sourceRadians, ILocated2D source, ILocated2D target,
			double allowance); static boolean onSideOf(ILocated2D source, double sourceRadians, ILocated2D other, boolean right); static double restrictRadians(double rads);  }