Пример #1
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);
            }
        }
Пример #2
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;
        }