From 018e8a0444168d83e8070531bf79eb3edc37f472 Mon Sep 17 00:00:00 2001 From: Jonathan Westhues Date: Thu, 8 May 2008 00:12:23 -0800 Subject: [PATCH] Draw an additional projection line, when showing a point-line projected distance constraint. [git-p4: depot-paths = "//depot/solvespace/": change = 1712] --- drawconstraint.cpp | 13 +++++++++++++ dsc.h | 1 + util.cpp | 12 ++++++++++++ 3 files changed, 26 insertions(+) diff --git a/drawconstraint.cpp b/drawconstraint.cpp index 0b9686a..0782724 100644 --- a/drawconstraint.cpp +++ b/drawconstraint.cpp @@ -151,6 +151,19 @@ void Constraint::DrawOrGetDistance(Vector *labelPos) { LineDrawOrGetDistance(pt, closest); Vector ref = ((closest.Plus(pt)).ScaledBy(0.5)).Plus(disp.offset); DoLabel(ref, labelPos, gr, gu); + + if(workplane.v != Entity::FREE_IN_3D.v) { + // Draw the projection marker from the closest point on the + // projected line to the projected point on the real line. + lAB = (lA.Minus(lB)); + double t = (lA.Minus(closest)).DivPivoting(lAB); + + Vector lA = SS.GetEntity(line->point[0])->PointGetNum(); + Vector lB = SS.GetEntity(line->point[1])->PointGetNum(); + + Vector c2 = (lA.ScaledBy(1-t)).Plus(lB.ScaledBy(t)); + DoProjectedPoint(&c2); + } break; } diff --git a/dsc.h b/dsc.h index 1da3023..b9441a5 100644 --- a/dsc.h +++ b/dsc.h @@ -48,6 +48,7 @@ public: Vector WithMagnitude(double s); Vector ScaledBy(double s); Vector ProjectInto(hEntity wrkpl); + double DivPivoting(Vector delta); }; class Point2d { diff --git a/util.cpp b/util.cpp index abb6fd9..c311018 100644 --- a/util.cpp +++ b/util.cpp @@ -275,6 +275,18 @@ Vector Vector::ProjectInto(hEntity wrkpl) { return p0.Plus((u.ScaledBy(up)).Plus(v.ScaledBy(vp))); } +double Vector::DivPivoting(Vector delta) { + double m = max(fabs(delta.x), max(fabs(delta.y), fabs(delta.z))); + + if(m == fabs(delta.x)) { + return x/delta.x; + } else if(m == fabs(delta.y)) { + return y/delta.y; + } else if(m == fabs(delta.z)) { + return z/delta.z; + } else oops(); +} + Point2d Point2d::Plus(Point2d b) { Point2d r; r.x = x + b.x;