From 2a420e84002ff8bea68a9bd77f29345594bc66b7 Mon Sep 17 00:00:00 2001 From: Jonathan Westhues Date: Tue, 26 Feb 2008 04:48:31 -0800 Subject: [PATCH] Infer the correct supplementary angle from the sketch. Equal angle applies to whichever is closer to original position, and angle constraint, if the two vectors are lines that share an endpoint, applies to vectors out from that shared point. [git-p4: depot-paths = "//depot/solvespace/": change = 1863] --- constraint.cpp | 35 +++++++++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/constraint.cpp b/constraint.cpp index 154b108..e34e0b6 100644 --- a/constraint.cpp +++ b/constraint.cpp @@ -233,6 +233,18 @@ void Constraint::MenuConstrain(int id) { " * two circles or arcs (equal radius)\r\n"); return; } + if(c.type == EQUAL_ANGLE) { + // Infer the nearest supplementary angle from the sketch. + Vector a1 = SS.GetEntity(c.entityA)->VectorGetNum(), + b1 = SS.GetEntity(c.entityB)->VectorGetNum(), + a2 = SS.GetEntity(c.entityC)->VectorGetNum(), + b2 = SS.GetEntity(c.entityD)->VectorGetNum(); + double d1 = a1.Dot(b1), d2 = a2.Dot(b2); + + if(d1*d2 < 0) { + c.other = true; + } + } AddConstraint(&c); break; @@ -477,13 +489,12 @@ void Constraint::MenuConstrain(int id) { Error("Must select a constraint with associated label."); return; - case GraphicsWindow::MNU_ANGLE: + case GraphicsWindow::MNU_ANGLE: { if(gs.vectors == 2 && gs.n == 2) { c.type = ANGLE; c.entityA = gs.vector[0]; c.entityB = gs.vector[1]; c.valA = 0; - c.other = true; } else { Error("Bad selection for angle constraint. This constraint " "can apply to:\r\n\r\n" @@ -492,9 +503,29 @@ void Constraint::MenuConstrain(int id) { " * two normals\r\n"); return; } + + Entity *ea = SS.GetEntity(c.entityA), + *eb = SS.GetEntity(c.entityB); + if(ea->type == Entity::LINE_SEGMENT && + eb->type == Entity::LINE_SEGMENT) + { + Vector a0 = SS.GetEntity(ea->point[0])->PointGetNum(), + a1 = SS.GetEntity(ea->point[1])->PointGetNum(), + b0 = SS.GetEntity(eb->point[0])->PointGetNum(), + b1 = SS.GetEntity(eb->point[1])->PointGetNum(); + if(a0.Equals(b0) || a1.Equals(b1)) { + // okay, vectors should be drawn in same sense + } else if(a0.Equals(b1) || a1.Equals(b0)) { + // vectors are in opposite sense + c.other = true; + } else { + // no shared point; not clear which intersection to draw + } + } c.ModifyToSatisfy(); AddConstraint(&c); break; + } case GraphicsWindow::MNU_PARALLEL: if(gs.vectors == 2 && gs.n == 2) {