User 870ab5b546
19-08-2013 14:03:16
The code:
public static boolean pointOnLine(DPoint3 p, MPolyline line,
boolean debugPrint) {
final String SELF = "VectorMath.pointOnLine: ";
// need to copy MPoint to get location to prevent infinite recursion in
// certain rare instances
final DPoint3 pt1 = (new MPoint(line.getPoint(0))).getLocation();
final DPoint3 pt2 = (new MPoint(line.getPoint(1))).getLocation();
final DPoint3 pt = new DPoint3(p.x, p.y, 0); // project onto XY plane
final DPoint3 vecTo1 = diff(new DPoint3(pt1.x, pt1.y, 0), pt);
final DPoint3 vecTo2 = diff(new DPoint3(pt2.x, pt2.y, 0), pt);
final double angle = angle(vecTo1, vecTo2);
final int endPt_pt_endPtAngle = MathMethods.roundToInt(
toDegrees(Math.abs(angle)));
if (debugPrint) debugPrint(SELF + "pt = ", p,
", original line endPt1 = ", line.getPoint(0).getLocation(),
", original line endPt2 = ", line.getPoint(1).getLocation(),
", endPt1 = ", pt1,
", endPt2 = ", pt2,
", vector to line origin = ", vecTo1,
", vector to line destination = ", vecTo2,
", raw endPt_pt_endPtAngle in radians = ", angle,
", rounded endPt_pt_endPtAngle in degrees = ",
endPt_pt_endPtAngle,
"; should be 180 +/- 10 to be found on line.");
return MathMethods.inRange(endPt_pt_endPtAngle, new int[] {170, 190});
} // pointOnLine(DPoint3, MPolyline, boolean)
Log output:
VectorMath.pointOnLine: pt = DPoint3(1.8591372966766357, 1.5148526430130005, 0.0),
original line endPt1 = DPoint3(-3.55684831738472, 9.937028884887695, 0.0),
original line endPt2 = DPoint3(-3.4905203878879547, 8.560417175292969, 0.0),
endPt1 = DPoint3(0.0, 0.0, 0.0),
endPt2 = DPoint3(0.0, 0.0, 0.0),
vector to line origin = DPoint3(-1.8591372966766357, -1.5148526430130005, 0.0),
vector to line destination = DPoint3(-1.8591372966766357, -1.5148526430130005, 0.0),
raw endPt_pt_endPtAngle in radians = 0.0, rounded endPt_pt_endPtAngle in degrees = 0;
should be 180 +/- 10 to be found on line.
Seems to me that the when the MPoint is copied, its location should be copied as well, but it seems clear that the location is not being copied into the new object. Am I missing something?