public override void FlipWithPlane(Vector3d p0, Vector3d normal) { VertexList vl = PointList; for (int i = 0; i < vl.Count; i++) { CadVertex v = vl[i]; Vector3d cp = CadMath.CrossPlane(v.vector, p0, normal); CadVertex d = v - cp; v = cp - d; vl[i] = v; } Vector3dList nl = mHeModel.NormalStore; for (int i = 0; i < nl.Count; i++) { Vector3d v = nl[i]; Vector3d cp = CadMath.CrossPlane(v, Vector3d.Zero, normal); Vector3d d = v - cp; v = cp - d; nl[i] = v; } }
public override void MoveSelectedPointsFromStored(DrawContext dc, Vector3d delta) { //base.MoveSelectedPoints(dc, delta); if (Locked) { return; } Vector3d d; if (!IsSelectedAll() && mPointList.Count > 2 && RestrictionByNormal) { Vector3d vdir = dc.ViewDir; Vector3d a = delta; Vector3d b = delta + vdir; d = CadMath.CrossPlane(a, b, StoreList[0].vector, Normal); if (!d.IsValid()) { Vector3d nvNormal = CadMath.Normal(Normal, vdir); double ip = CadMath.InnerProduct(nvNormal, delta); d = nvNormal * ip; } } else { d = delta; } FigUtil.MoveSelectedPointsFromStored(this, dc, d); mChildList.ForEach(c => { c.MoveSelectedPointsFromStored(dc, delta); }); }
public RulerInfo Capture(DrawContext dc, CadCursor cursor, double range) { RulerInfo ret = default(RulerInfo); Vector3d cwp = dc.DevPointToWorldPoint(cursor.Pos); Vector3d xfaceNormal = dc.DevVectorToWorldVector(cursor.DirX); Vector3d yfaceNormal = dc.DevVectorToWorldVector(cursor.DirY); Vector3d cx = CadMath.CrossPlane(P0, P1, cwp, xfaceNormal); Vector3d cy = CadMath.CrossPlane(P0, P1, cwp, yfaceNormal); if (!cx.IsValid() && !cy.IsValid()) { return(ret); } Vector3d p = VectorExt.InvalidVector3d; double mind = Double.MaxValue; StackArray <Vector3d> vtbl = default; vtbl[0] = cx; vtbl[1] = cy; vtbl.Length = 2; for (int i = 0; i < vtbl.Length; i++) { Vector3d v = vtbl[i]; if (!v.IsValid()) { continue; } Vector3d devv = dc.WorldPointToDevPoint(v); double td = (devv - cursor.Pos).Norm(); if (td < mind) { mind = td; p = v; } } if (!p.IsValid()) { return(ret); } if (mind > range) { return(ret); } ret.IsValid = true; ret.CrossPoint = p; ret.Distance = mind; ret.Ruler = this; return(ret); }
public override void MoveSelectedPointsFromStored(DrawContext dc, Vector3d delta) { if (PointList[0].Selected && PointList[1].Selected && PointList[2].Selected && PointList[3].Selected) { PointList[0] = StoreList[0] + delta; PointList[1] = StoreList[1] + delta; PointList[2] = StoreList[2] + delta; PointList[3] = StoreList[3] + delta; return; } if (PointList[2].Selected || PointList[3].Selected) { Vector3d v0 = StoreList[3].vector - StoreList[0].vector; if (v0.IsZero()) { // 移動方向が不定の場合 MoveSelectedPointWithHeight(dc, delta); return; } Vector3d v0u = v0.UnitVector(); double d = CadMath.InnerProduct(v0u, delta); Vector3d vd = v0u * d; CadVertex nv3 = StoreList[3] + vd; CadVertex nv2 = StoreList[2] + vd; if (nv3.EqualsThreshold(StoreList[0], 0.001) || nv2.EqualsThreshold(StoreList[1], 0.001)) { return; } PointList[3] = nv3; PointList[2] = nv2; return; } if (PointList[0].Selected || PointList[1].Selected) { Vector3d v0 = StoreList[0].vector; Vector3d v1 = StoreList[1].vector; Vector3d v2 = StoreList[2].vector; Vector3d v3 = StoreList[3].vector; Vector3d lv = v3 - v0; double h = lv.Norm(); Vector3d planeNormal = CadMath.Normal(v0, v1, v2); Vector3d cp0 = v0; Vector3d cp1 = v1; if (PointList[0].Selected) { cp0 = CadMath.CrossPlane(v0 + delta, v0, planeNormal); } if (PointList[1].Selected) { cp1 = CadMath.CrossPlane(v1 + delta, v1, planeNormal); } if (cp0.EqualsThreshold(cp1, 0.001)) { return; } if (PointList[0].Selected) { PointList[0] = PointList[0].SetVector(cp0); } if (PointList[1].Selected) { PointList[1] = PointList[1].SetVector(cp1); } Vector3d normal = CadMath.Normal(cp0, cp0 + planeNormal, cp1); Vector3d d = normal * h; PointList[3] = PointList[3].SetVector(PointList[0] + d); PointList[2] = PointList[2].SetVector(PointList[1] + d); } }
private void CheckCircle(DrawContext dc, CadLayer layer, CadFigure fig) { if (fig.PointCount < 3) { return; } VertexList vl = fig.PointList; if (fig.StoreList != null) { vl = fig.StoreList; } Vector3d c = vl[0].vector; Vector3d a = vl[1].vector; Vector3d b = vl[2].vector; Vector3d normal = CadMath.Normal(a - c, b - c); Vector3d tw = Target.Pos; tw.Z = 0; tw = dc.DevPointToWorldPoint(tw); Vector3d crossP = CadMath.CrossPlane(tw, tw + dc.ViewDir, c, normal); if (crossP.IsInvalid()) { // 真横から見ている場合 // viewed edge-on //DOut.tpl("crossP is invalid"); return; } double r = (a - c).Norm(); double tr = (crossP - c).Norm(); Vector3d cirP = c + (crossP - c) * (r / tr); Vector3d dcirP = dc.WorldPointToDevPoint(cirP); Vector3d dcrossP = dc.WorldPointToDevPoint(crossP); dcirP.Z = 0; dcrossP.Z = 0; double dist = (dcirP - Target.Pos).Norm(); if (dist > Range) { //DOut.tpl($"dist:{dist} Range:{Range}"); return; } if (dist < MinDist) { FigureSegment fseg = new FigureSegment(fig, 0, 0, 0); MarkSeg.Layer = layer; MarkSeg.FigSeg = fseg; MarkSeg.CrossPoint = cirP; MarkSeg.CrossPointScrn = dc.WorldPointToDevPoint(cirP); MarkSeg.Distance = dist; MinDist = dist; } }