示例#1
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;
                }
            }
示例#2
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);
        }
示例#3
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);
            }
        }
示例#4
0
        public override void MoveSelectedPointsFromStored(DrawContext dc, Vector3d delta)
        {
            CadVertex cp = StoreList[0];

            if (cp.Selected)
            {
                mPointList[0] = cp + delta;
                mPointList[1] = StoreList[1] + delta;
                mPointList[2] = StoreList[2] + delta;
                mPointList[3] = StoreList[3] + delta;
                mPointList[4] = StoreList[4] + delta;
                return;
            }

            StackArray <CadVertex> vt = default;

            vt[0]     = StoreList[1] - cp;
            vt[1]     = StoreList[2] - cp;
            vt[2]     = StoreList[3] - cp;
            vt[3]     = StoreList[4] - cp;
            vt.Length = 4;

            if (vt[0].Norm() < 0.01)
            {
                return;
            }

            int ai = -1;

            for (int i = 0; i < 4; i++)
            {
                if (StoreList[i + 1].Selected)
                {
                    ai = i;
                    break;
                }
            }

            if (ai < 0)
            {
                return;
            }

            int bi = (ai + 1) % 4;
            int ci = (ai + 2) % 4;
            int di = (ai + 3) % 4;

            Vector3d normal = CadMath.CrossProduct(vt[ai].vector, vt[bi].vector);

            normal = normal.UnitVector();

            vt[ai] += delta;

            CadVertex uva = vt[ai].UnitVector();
            CadVertex uvb = vt[bi].UnitVector();

            if (!uva.EqualsThreshold(uvb))
            {
                normal = CadMath.CrossProduct(vt[ai].vector, vt[bi].vector);

                if (normal.IsZero())
                {
                    return;
                }

                normal = normal.UnitVector();
            }

            CadQuaternion q = CadQuaternion.RotateQuaternion(normal, Math.PI / 2.0);
            CadQuaternion r = q.Conjugate();

            CadQuaternion qp = CadQuaternion.FromPoint(vt[ai].vector);

            qp = r * qp;
            qp = qp * q;

            vt[bi] = (CadVertex)qp.ToPoint();

            vt[ci] = -vt[ai];
            vt[di] = -vt[bi];

            CadVertex tmp;

            for (int i = 0; i < vt.Length; i++)
            {
                tmp          = vt[i];
                tmp.Selected = false;
                vt[i]        = tmp;
            }

            tmp          = vt[ai];
            tmp.Selected = true;
            vt[ai]       = tmp;

            mPointList[1] = vt[0] + cp;
            mPointList[2] = vt[1] + cp;
            mPointList[3] = vt[2] + cp;
            mPointList[4] = vt[3] + cp;
        }