Exemple #1
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);
        }
Exemple #2
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);
        }
Exemple #3
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);
        }