コード例 #1
0
        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;
            }
        }
コード例 #2
0
        // 法線の代表値を求める
        //public static CadVertex RepresentativeNormal(VertexList points)
        //{
        //    if (points.Count < 3)
        //    {
        //        return CadVertex.Zero;
        //    }

        //    int idx = FindMaxDistantPointIndex(points[0], points);

        //    int idxA = idx - 1;
        //    int idxB = idx + 1;

        //    if (idxA < 0)
        //    {
        //        idxA = points.Count - 1;
        //    }

        //    if (idxB >= points.Count)
        //    {
        //        idxB = idxB - points.Count;
        //    }

        //    CadVertex normal = CadMath.Normal(points[idx], points[idxA], points[idxB]);

        //    return normal;
        //}

        public static Vector3d TypicalNormal(VertexList points)
        {
            if (points.Count < 3)
            {
                return(Vector3d.Zero);
            }

            int idx = FindMaxDistantPointIndex(points[0], points);

            int idxA = idx - 1;
            int idxB = idx + 1;

            if (idxA < 0)
            {
                idxA = points.Count - 1;
            }

            if (idxB >= points.Count)
            {
                idxB = idxB - points.Count;
            }

            Vector3d normal = CadMath.Normal(points[idx].vector, points[idxA].vector, points[idxB].vector);

            return(normal);
        }
コード例 #3
0
        private void drawCircle(DrawContext dc, DrawPen pen)
        {
            if (PointList.Count == 0)
            {
                return;
            }

            if (PointList.Count == 1)
            {
                dc.Drawing.DrawCross(pen, PointList[0].vector, 2);
                if (PointList[0].Selected)
                {
                    dc.Drawing.DrawSelectedPoint(PointList[0].vector, dc.GetPen(DrawTools.PEN_SELECT_POINT));
                }
                return;
            }

            Vector3d normal = CadMath.Normal(PointList[0].vector, PointList[2].vector, PointList[1].vector);

            CircleExpander.Draw(PointList[0], PointList[1], PointList[2], 32, dc, pen);

            double size = dc.DevSizeToWoldSize(4);

            dc.Drawing.DrawCross(pen, PointList[0].vector, size);
        }
コード例 #4
0
            public override void AddPointInCreating(DrawContext dc, CadVertex p)
            {
                if (Figure.mPointList.Count == 0)
                {
                    Figure.mPointList.Add(p);
                }
                else
                {
                    Vector3d p0 = Figure.PointList[0].vector;
                    Vector3d p2 = p.vector;

                    Vector3d hv = CadMath.CrossProduct(dc.UpVector, dc.ViewDir).Normalized();
                    Vector3d uv = dc.UpVector;

                    Vector3d crossV = p2 - p0;

                    Vector3d v1 = CadMath.InnerProduct(crossV, hv) * hv;
                    Vector3d p1 = v1 + p0;

                    Vector3d v3 = CadMath.InnerProduct(crossV, uv) * uv;
                    Vector3d p3 = v3 + p0;

                    Figure.mPointList.Add(new CadVertex(p3));
                    Figure.mPointList.Add(new CadVertex(p2));
                    Figure.mPointList.Add(new CadVertex(p1));

                    Figure.IsLoop = true;
                }
            }
コード例 #5
0
        private static bool ListContainsPointInTriangle(VertexList check, CadFigure triangle)
        {
            var tps = triangle.PointList;

            foreach (CadVertex cp in check)
            {
                if (
                    cp.Equals(tps[0]) ||
                    cp.Equals(tps[1]) ||
                    cp.Equals(tps[2])
                    )
                {
                    continue;
                }

                bool ret = CadMath.IsPointInTriangle(
                    cp.vector,
                    tps[0].vector,
                    tps[1].vector,
                    tps[2].vector
                    );
                if (ret)
                {
                    return(true);
                }
            }

            return(false);
        }
コード例 #6
0
 // 三角形の重心を求める
 public static Vector3d TriangleCentroid(CadFigure fig)
 {
     return(CadMath.TriangleCentroid(
                fig.GetPointAt(0).vector,
                fig.GetPointAt(1).vector,
                fig.GetPointAt(2).vector
                ));
 }
コード例 #7
0
 private Vector3d CrossLineScr(SegmentItem seg0, SegmentItem seg1)
 {
     return(CadMath.CrossLine2D(
                seg0.ScrSegment.P0.vector,
                seg0.ScrSegment.P1.vector,
                seg1.ScrSegment.P0.vector,
                seg1.ScrSegment.P1.vector));
 }
コード例 #8
0
 private bool CheckCrossSegSegScr(SegmentItem seg0, SegmentItem seg1)
 {
     return(CadMath.CheckCrossSegSeg2D(
                seg0.ScrSegment.P0.vector,
                seg0.ScrSegment.P1.vector,
                seg1.ScrSegment.P0.vector,
                seg1.ScrSegment.P1.vector));
 }
コード例 #9
0
 // 三角形の面積 3D対応
 public static double TriangleArea(CadFigure fig)
 {
     return(CadMath.TriangleArea(
                fig.GetPointAt(0).vector,
                fig.GetPointAt(1).vector,
                fig.GetPointAt(2).vector
                ));
 }
コード例 #10
0
        public void RotateEyePoint(Vector2 prev, Vector2 current)
        {
            Vector2 d = current - prev;

            double ry = (d.X / 10.0) * (Math.PI / 20);
            double rx = (d.Y / 10.0) * (Math.PI / 20);

            CadQuaternion q;
            CadQuaternion r;
            CadQuaternion qp;

            q = CadQuaternion.RotateQuaternion(Vector3d.UnitY, ry);

            r = q.Conjugate();

            qp   = CadQuaternion.FromVector(mEye);
            qp   = r * qp;
            qp   = qp * q;
            mEye = qp.ToVector3d();

            qp        = CadQuaternion.FromVector(mUpVector);
            qp        = r * qp;
            qp        = qp * q;
            mUpVector = qp.ToVector3d();

            Vector3d ev = mLookAt - mEye;

            Vector3d a = new Vector3d(ev);
            Vector3d b = new Vector3d(mUpVector);

            Vector3d axis = CadMath.Normal(a, b);

            if (!axis.IsZero())
            {
                q = CadQuaternion.RotateQuaternion(axis, rx);

                r = q.Conjugate();

                qp = CadQuaternion.FromVector(mEye);
                qp = r * qp;
                qp = qp * q;

                mEye = qp.ToVector3d();

                qp        = CadQuaternion.FromVector(mUpVector);
                qp        = r * qp;
                qp        = qp * q;
                mUpVector = qp.ToVector3d();
            }

            CalcViewMatrix();
            CalcViewDir();
            CalcProjectionZW();
        }
コード例 #11
0
        public Vector3d DistanceY(Vector3d pixp)
        {
            Vector3d a1 = Pos;
            Vector3d a2 = Pos + DirX;

            Vector3d b1 = pixp;
            Vector3d b2 = pixp + DirY;

            Vector3d c = CadMath.CrossLine2D(a1, a2, b1, b2);

            return(pixp - c);
        }
コード例 #12
0
        private void CheckFigPoint(DrawContext dc, Vector3d pt, CadLayer layer, CadFigure fig, int ptIdx)
        {
            Vector3d ppt = dc.WorldPointToDevPoint(pt);

            double dx = Math.Abs(ppt.X - Target.Pos.X);
            double dy = Math.Abs(ppt.Y - Target.Pos.Y);

            CrossInfo cix = CadMath.PerpCrossLine(Target.Pos, Target.Pos + Target.DirX, ppt);
            CrossInfo ciy = CadMath.PerpCrossLine(Target.Pos, Target.Pos + Target.DirY, ppt);

            double nx = (ppt - ciy.CrossPoint).Norm(); // Cursor Y軸からの距離
            double ny = (ppt - cix.CrossPoint).Norm(); // Cursor X軸からの距離

            if (nx <= Range)
            {
                if (nx < XMatch.DistanceX || (nx == XMatch.DistanceX && ny < XMatch.DistanceY))
                {
                    XMatch = GetMarkPoint(pt, ppt, nx, ny, layer, fig, ptIdx);
                }
            }

            if (ny <= Range)
            {
                if (ny < YMatch.DistanceY || (ny == YMatch.DistanceY && nx < YMatch.DistanceX))
                {
                    YMatch = GetMarkPoint(pt, ppt, nx, ny, layer, fig, ptIdx);
                }
            }

            if (dx <= Range && dy <= Range)
            {
                double minDist = (XYMatch.DistanceX * XYMatch.DistanceX) + (XYMatch.DistanceY * XYMatch.DistanceY);
                double curDist = (dx * dx) + (dy * dy);

                if (curDist <= minDist)
                {
                    MarkPoint t = GetMarkPoint(pt, ppt, dx, dy, layer, fig, ptIdx);

                    //t.dump();

                    XYMatch = t;

                    if (!XYMatchSet.Contains(t))
                    {
                        XYMatchList.Add(XYMatch);
                        XYMatchSet.Add(XYMatch);
                        //DOut.pl($"PointSearcher XYMatchList cnt:{XYMatchList.Count}");
                    }
                }
            }
        }
コード例 #13
0
        public void DrawHarfEdgeModel(
            DrawBrush brush, DrawPen pen, DrawPen edgePen, double edgeThreshold, HeModel model)
        {
            for (int i = 0; i < model.FaceStore.Count; i++)
            {
                HeFace f = model.FaceStore[i];

                HalfEdge head = f.Head;

                HalfEdge c = head;

                HalfEdge pair;

                for (; ;)
                {
                    bool edge = false;

                    pair = c.Pair;

                    if (pair == null)
                    {
                        edge = true;
                    }
                    else
                    {
                        double s = CadMath.InnerProduct(model.NormalStore[c.Normal], model.NormalStore[pair.Normal]);

                        if (Math.Abs(s) < edgeThreshold)
                        {
                            edge = true;
                        }
                    }

                    HalfEdge next = c.Next;

                    DrawPen dpen = edge ? edgePen : pen;

                    DrawLine(dpen,
                             model.VertexStore.Ref(c.Vertex).vector,
                             model.VertexStore.Ref(next.Vertex).vector
                             );

                    c = next;

                    if (c == head)
                    {
                        break;
                    }
                }
            }
        }
コード例 #14
0
        private void DrawTextScrn(int font, DrawBrush brush, Vector3d a, Vector3d dir, DrawTextOption opt, string s)
        {
            if (brush.GdiBrush == null)
            {
                return;
            }
            if (DC.Font(font) == null)
            {
                return;
            }

            if (opt.Option != 0)
            {
                Vector3d sz = MeasureText(font, s);

                if ((opt.Option | DrawTextOption.H_CENTER) != 0)
                {
                    double slen = sz.X / 2;

                    Vector3d ud = Vector3d.UnitX;

                    if (!dir.IsZero())
                    {
                        ud = dir.UnitVector();
                    }

                    a = a - (ud * slen);
                }
            }

            double angle = 0;

            if (!(dir.X == 0 && dir.Y == 0))
            {
                angle = CadMath.Angle2D(dir);
            }

            angle = CadMath.Rad2Deg(angle);

            DC.GdiGraphics.TranslateTransform((int)a.X, (int)a.Y);

            DC.GdiGraphics.RotateTransform((float)angle);

            Font  f = DC.Font(font);
            Brush b = brush.GdiBrush;

            DC.GdiGraphics.DrawString(s, f, b, 0, 0);

            DC.GdiGraphics.ResetTransform();
        }
コード例 #15
0
        public void PanCamera(DrawContext dc, Vector2 prev, Vector2 current)
        {
            Vector2 d = current - prev;

            double rx = d.X * (Math.PI / 1000);
            double ry = d.Y * (Math.PI / 1000);

            CadQuaternion q;
            CadQuaternion r;
            CadQuaternion qp;

            Vector3d lookv = dc.LookAt - dc.Eye;
            Vector3d upv   = dc.UpVector;

            q = CadQuaternion.RotateQuaternion(upv, rx);
            r = q.Conjugate();

            qp    = CadQuaternion.FromVector(lookv);
            qp    = r * qp;
            qp    = qp * q;
            lookv = qp.ToVector3d();

            Vector3d ev = dc.LookAt - dc.Eye;

            Vector3d a = new Vector3d(ev);
            Vector3d b = new Vector3d(upv);

            Vector3d axis = CadMath.Normal(a, b);

            if (!axis.IsZero())
            {
                q = CadQuaternion.RotateQuaternion(axis, ry);
                r = q.Conjugate();

                qp = CadQuaternion.FromVector(lookv);
                qp = r * qp;
                qp = qp * q;

                lookv = qp.ToVector3d();

                qp  = CadQuaternion.FromVector(upv);
                qp  = r * qp;
                qp  = qp * q;
                upv = qp.ToVector3d();
            }

            dc.SetCamera(dc.Eye, lookv + dc.Eye, upv);
        }
コード例 #16
0
        private Vector3d getRP(DrawContext dc, CadVertex cp, CadVertex p, bool isA)
        {
            if (p.Equals(cp))
            {
                return(cp.vector);
            }


            Vector3d r = CadMath.CrossProduct(p.vector - cp.vector, dc.ViewDir);

            r = r.UnitVector();

            r = r * (p.vector - cp.vector).Norm() + cp.vector;

            return(r);
        }
コード例 #17
0
        public static void ForEachSegs(
            CadVertex cp, CadVertex pa, CadVertex pb,
            int splitCnt,
            Action <CadVertex, CadVertex> action)
        {
            CadVertex va = pa - cp;
            CadVertex vb = pb - cp;

            if (va.Norm() < 0.01)
            {
                return;
            }


            double dt = (2.0 * Math.PI) / (double)splitCnt;

            int div = splitCnt;

            Vector3d normal = CadMath.Normal(va.vector, vb.vector);

            CadQuaternion q = CadQuaternion.RotateQuaternion(normal, dt);
            CadQuaternion r = q.Conjugate();

            CadVertex p   = va;
            CadVertex tp1 = pa;
            CadVertex tp2 = pa;


            int i = 0;

            for (; i < div - 1; i++)
            {
                CadQuaternion qp = CadQuaternion.FromPoint(p.vector);
                qp = r * qp;
                qp = qp * q;

                p.vector = qp.ToPoint();

                tp2 = p + cp;

                action(tp1, tp2);
                tp1 = tp2;
            }

            action(tp1, pa);
        }
コード例 #18
0
        public static void Draw(
            CadVertex cp, CadVertex pa, CadVertex pb,
            int splitCnt,
            DrawContext dc, DrawPen pen)
        {
            CadVertex va = pa - cp;
            CadVertex vb = pb - cp;

            if (va.Norm() < 0.01)
            {
                return;
            }

            double dt = (2.0 * Math.PI) / (double)splitCnt;

            int div = splitCnt;

            Vector3d normal = CadMath.Normal(va.vector, vb.vector);

            CadQuaternion q = CadQuaternion.RotateQuaternion(normal, dt);
            CadQuaternion r = q.Conjugate();

            CadVertex p   = va;
            CadVertex tp1 = pa;
            CadVertex tp2 = pa;


            int i = 0;

            for (; i < div - 1; i++)
            {
                CadQuaternion qp = CadQuaternion.FromPoint(p.vector);
                qp = r * qp;
                qp = qp * q;

                p.vector = qp.ToPoint();

                tp2 = p + cp;

                dc.Drawing.DrawLine(pen, tp1.vector, tp2.vector);
                tp1 = tp2;
            }

            dc.Drawing.DrawLine(pen, tp1.vector, pa.vector);
        }
コード例 #19
0
        //
        // 点pを通り、a - b に平行で、a-bに垂直な線分を求める
        //
        //   +----------p------------+
        //   |                       |
        //   |                       |
        //   a                       b
        //
        public static CadSegment PerpSeg(CadVertex a, CadVertex b, CadVertex p)
        {
            CadSegment seg = default(CadSegment);

            seg.P0 = a;
            seg.P1 = b;

            CrossInfo ci = CadMath.PerpCrossLine(a.vector, b.vector, p.vector);

            if (ci.IsCross)
            {
                CadVertex nv = p - ci.CrossPoint;

                seg.P0 += nv;
                seg.P1 += nv;
            }

            return(seg);
        }
コード例 #20
0
        public void DrawAxis()
        {
            Vector3d p0;
            Vector3d p1;

            double wh = Math.Min(DC.ViewWidth, DC.ViewHeight) / 2;


            //double len = DrawingConst.AxisLength;
            //double arrowLen = 4.0 / DC.WorldScale;
            //double arrowW2 = 2.0 / DC.WorldScale;

            double len      = DC.DevSizeToWoldSize(wh - AXIS_MARGIN) * DC.WorldScale;
            double arrowLen = DC.DevSizeToWoldSize(16) * DC.WorldScale;
            double arrowW2  = DC.DevSizeToWoldSize(8) * DC.WorldScale;

            // X軸
            p0 = new Vector3d(-len, 0, 0) / DC.WorldScale;
            p1 = new Vector3d(len, 0, 0) / DC.WorldScale;

            if (!CadMath.IsParallel(p1 - p0, (Vector3d)DC.ViewDir))
            {
                DrawArrow(DC.GetPen(DrawTools.PEN_AXIS_X), p0, p1, ArrowTypes.CROSS, ArrowPos.END, arrowLen, arrowW2);
            }

            // Y軸
            p0 = new Vector3d(0, -len, 0) / DC.WorldScale;
            p1 = new Vector3d(0, len, 0) / DC.WorldScale;

            if (!CadMath.IsParallel(p1 - p0, (Vector3d)DC.ViewDir))
            {
                DrawArrow(DC.GetPen(DrawTools.PEN_AXIS_Y), p0, p1, ArrowTypes.CROSS, ArrowPos.END, arrowLen, arrowW2);
            }

            // Z軸
            p0 = new Vector3d(0, 0, -len) / DC.WorldScale;
            p1 = new Vector3d(0, 0, len) / DC.WorldScale;

            if (!CadMath.IsParallel(p1 - p0, (Vector3d)DC.ViewDir))
            {
                DrawArrow(DC.GetPen(DrawTools.PEN_AXIS_Z), p0, p1, ArrowTypes.CROSS, ArrowPos.END, arrowLen, arrowW2);
            }
        }
コード例 #21
0
        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);
            });
        }
コード例 #22
0
        public static EditResult CutSegment(CadObjectDB db, MarkSegment seg, Vector3d p)
        {
            EditResult result = new EditResult();

            if (seg.Figure.Type != CadFigure.Types.POLY_LINES)
            {
                return(result);
            }

            CrossInfo ci = CadMath.PerpendicularCrossSeg(seg.pA.vector, seg.pB.vector, p);

            if (!ci.IsCross)
            {
                return(result);
            }

            CadFigure org = db.GetFigure(seg.FigureID);

            int a = Math.Min(seg.PtIndexA, seg.PtIndexB);
            int b = Math.Max(seg.PtIndexA, seg.PtIndexB);


            CadFigure fa = db.NewFigure(CadFigure.Types.POLY_LINES);
            CadFigure fb = db.NewFigure(CadFigure.Types.POLY_LINES);

            fa.AddPoints(org.PointList, 0, a + 1);
            fa.AddPoint(new CadVertex(ci.CrossPoint));

            fb.AddPoint(new CadVertex(ci.CrossPoint));
            fb.AddPoints(org.PointList, b);

            if (org.IsLoop)
            {
                fb.AddPoint(fa.GetPointAt(0));
            }

            result.AddList.Add(new EditResult.Item(seg.LayerID, fa));
            result.AddList.Add(new EditResult.Item(seg.LayerID, fb));
            result.RemoveList.Add(new EditResult.Item(org.LayerID, org));

            return(result);
        }
コード例 #23
0
        private void DrawDim(
            DrawContext dc,
            CadVertex a,
            CadVertex b,
            CadVertex p,
            DrawPen pen)
        {
            CadSegment seg = CadUtil.PerpSeg(a, b, p);

            dc.Drawing.DrawLine(pen, a.vector, seg.P0.vector);
            dc.Drawing.DrawLine(pen, b.vector, seg.P1.vector);

            Vector3d cp = CadMath.CenterPoint(seg.P0.vector, seg.P1.vector);

            double arrowW = ARROW_W;
            double arrowL = ARROW_LEN;

            dc.Drawing.DrawArrow(pen, cp, seg.P0.vector, ArrowTypes.CROSS, ArrowPos.END, arrowL, arrowW);
            dc.Drawing.DrawArrow(pen, cp, seg.P1.vector, ArrowTypes.CROSS, ArrowPos.END, arrowL, arrowW);
        }
コード例 #24
0
        private void DrawDim(DrawContext dc, DrawPen linePen, DrawBrush textBrush)
        {
            dc.Drawing.DrawLine(linePen, PointList[0].vector, PointList[3].vector);
            dc.Drawing.DrawLine(linePen, PointList[1].vector, PointList[2].vector);

            Vector3d cp = CadMath.CenterPoint(PointList[3].vector, PointList[2].vector);

            double arrowW = ARROW_W;
            double arrowL = ARROW_LEN;

            double ww = (PointList[1] - PointList[0]).Norm() / 4.0;

            if (ww > arrowL)
            {
                dc.Drawing.DrawArrow(linePen, cp, PointList[3].vector, ArrowTypes.CROSS, ArrowPos.END, arrowL, arrowW);
                dc.Drawing.DrawArrow(linePen, cp, PointList[2].vector, ArrowTypes.CROSS, ArrowPos.END, arrowL, arrowW);
            }
            else
            {
                Vector3d v0 = cp - PointList[3].vector;
                Vector3d v1 = cp - PointList[2].vector;

                v0 = -(v0.Normalized() * (arrowL * 1.5)) / dc.WorldScale + PointList[3].vector;
                v1 = -(v1.Normalized() * (arrowL * 1.5)) / dc.WorldScale + PointList[2].vector;

                dc.Drawing.DrawArrow(linePen, v0, PointList[3].vector, ArrowTypes.CROSS, ArrowPos.END, arrowL, arrowW);
                dc.Drawing.DrawArrow(linePen, v1, PointList[2].vector, ArrowTypes.CROSS, ArrowPos.END, arrowL, arrowW);

                dc.Drawing.DrawLine(linePen, PointList[2].vector, PointList[3].vector);
            }

            CadVertex lineV = PointList[2] - PointList[3];

            double len = lineV.Norm();

            string lenStr = CadUtil.ValToString(len);

            CadVertex p = PointList[3] + (lineV / 2);

            p += (PointList[3] - PointList[0]).UnitVector() * (arrowW);

            CadVertex up = PointList[3] - PointList[0];

            // 裏返しになる場合は、反転する
            // If it turns over, reverse it
            Vector3d normal = CadMath.Normal(lineV.vector, up.vector);

            double scala = CadMath.InnerProduct(normal, dc.ViewDir);

            if (scala > 0)
            {
                lineV = -lineV;
            }

            //             --- lineV --->
            //    3<------------ p ----------->2
            // ^  |                            |
            // |  |                            |
            // up 0                            1
            //
            dc.Drawing.DrawText(FontID, textBrush, p.vector, lineV.vector, up.vector,
                                new DrawTextOption(DrawTextOption.H_CENTER),
                                lenStr);
        }
コード例 #25
0
        public static void DrawArrow(
            Action <DrawPen, Vector3d, Vector3d> DrawLine,
            DrawPen pen,
            Vector3d pt0,
            Vector3d pt1,
            ArrowTypes type,
            ArrowPos pos,
            double len,
            double width)
        {
            DrawLine(pen, pt0, pt1);

            Vector3d d = pt1 - pt0;

            double dl = d.Length;

            if (dl < 0.00001)
            {
                return;
            }


            Vector3d tmp = new Vector3d(dl, 0, 0);

            double angle = Vector3d.CalculateAngle(tmp, d);

            Vector3d normal = CadMath.CrossProduct(tmp, d);  // 回転軸

            if (normal.Length < 0.0001)
            {
                normal = new Vector3d(0, 0, 1);
            }
            else
            {
                normal = normal.UnitVector();
                normal = CadMath.Normal(tmp, d);
            }

            CadQuaternion q = CadQuaternion.RotateQuaternion(normal, -angle);
            CadQuaternion r = q.Conjugate();

            ArrowHead a;

            if (pos == ArrowPos.END || pos == ArrowPos.START_END)
            {
                a = ArrowHead.Create(type, ArrowPos.END, len, width);

                a.Rotate(q, r);

                a += pt1;

                DrawLine(pen, a.p0.vector, a.p1.vector);
                DrawLine(pen, a.p0.vector, a.p2.vector);
                DrawLine(pen, a.p0.vector, a.p3.vector);
                DrawLine(pen, a.p0.vector, a.p4.vector);
            }

            if (pos == ArrowPos.START || pos == ArrowPos.START_END)
            {
                a = ArrowHead.Create(type, ArrowPos.START, len, width);

                a.Rotate(q, r);

                a += pt0;

                DrawLine(pen, a.p0.vector, a.p1.vector);
                DrawLine(pen, a.p0.vector, a.p2.vector);
                DrawLine(pen, a.p0.vector, a.p3.vector);
                DrawLine(pen, a.p0.vector, a.p4.vector);
            }
        }
コード例 #26
0
 static CadFigureMesh()
 {
     EDGE_THRESHOLD = Math.Cos(CadMath.Deg2Rad(30));
 }
コード例 #27
0
 // 三角形で設定
 public void set(Vector3d p0, Vector3d p1, Vector3d p2)
 {
     Area  = CadMath.TriangleArea(p0, p1, p2);
     Point = CadMath.TriangleCentroid(p0, p1, p2);
 }
コード例 #28
0
        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);
            }
        }
コード例 #29
0
        protected void DrawCircleScrn(DrawPen pen, Vector3d cp, Vector3d p1)
        {
            double r = CadMath.SegNorm(cp, p1);

            DrawCircleScrn(pen, cp, r);
        }
コード例 #30
0
        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);
        }