Exemplo n.º 1
0
        /// <summary>
        /// 線対称の位置を計算
        /// </summary>
        /// <param name="v"></param>
        /// <param name="start">線対称の線の始点</param>
        /// <param name="end">線対称の線の終点</param>
        /// <returns></returns>
        Vector2 CalcSymmetricPoint(Vector2 v, Vector2 start, Vector2 end)
        {
            var v0 = end - start;
            var a0 = MathF.Atan2(v0.Y, v0.X);
            var v1 = v - start;
            var a1 = MathF.Atan2(v1.Y, v1.X);
            var a  = a0 - (a1 - a0);
            var l  = CmUtils.Length(v, start);

            Vector2 vn = new Vector2(l * MathF.Cos(a), l * MathF.Sin(a));

            vn += start;
            return(vn);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 直線をベジェに変換、コントロールポイントは直線上に1/3の長さで設定
        /// </summary>
        /// <returns></returns>
        internal bool ConvertToCurve()
        {
            var p0  = befor.GetPoint();
            var p1  = GetPoint();
            var l   = CmUtils.Length(p0, p1) / 3;
            var rad = MathF.Atan2(p1.Y - p0.Y, p1.X - p0.X);

            points.Insert(0, CmUtils.Coordinate(p0, l, rad));
            points.Insert(1, CmUtils.Coordinate(p1, l, rad + MathF.PI));
            Command = 'C';


            return(true);
        }
Exemplo n.º 3
0
        bool RoundSub(Vector2 pc, Vector2 pb, Vector2 pn, ref Vector2 pb2, ref Vector2 pn2, float step)
        {
            var a1 = MathF.Atan2(pc.Y - pb.Y, pc.X - pb.X); //傾き
            var a2 = MathF.Atan2(pn.Y - pc.Y, pn.X - pc.X); //次の線の傾き

            var a = (a1 + a2) / 2;

            a = MathF.Abs(a);
            if (a > MathF.PI)
            {
                a -= MathF.PI;
            }
            // a は中線の傾き

            float lb2 = CmUtils.Length(pc, pb2);
            float ln2 = CmUtils.Length(pc, pn2);
            float l   = MathF.Min(lb2, ln2);

            var ac2 = MathF.Abs((a1 - a2) / 2);

            if (ac2 > MathF.PI)
            {
                ac2 -= MathF.PI;
            }

            float r = l * MathF.Tan(ac2);

            r = MathF.Round(r, 1);
            if (step > 0)
            {
                if (r < 2)
                {
                    step = 0.1f;
                }
                else if (r < 2.4)
                {
                    step = 2.4f - r;
                }
                else
                {
                    step = 0.1f;
                }
            }
            else
            {
                if (r <= 2.0f)
                {
                    step = -0.1f;
                }
                else if (r < 2.5)
                {
                    step = 2.0f - r;
                }
                else
                {
                    step = -0.5f;
                }
            }
            r += step;
            ///

            float v = 0;

            v = r / MathF.Tan(a);              // 半径r円の接点の頂点からの距離
            float l1 = CmUtils.Length(pb, pc); // 自分の線の長さ
            float l2 = CmUtils.Length(pc, pn); // 次の線の長さ

            if (l1 < v || l2 < v)
            {
                return(false);
            }



            var x  = MathF.Cos(a1) * v;
            var y  = MathF.Sin(a1) * v;
            var p1 = new Vector2(pc.X - x, pc.Y - y);

            x = MathF.Cos(a2) * v;
            y = MathF.Sin(a2) * v;
            var p2 = new Vector2(pc.X + x, pc.Y + y);


            var c = r * 0.5522847f; // 半径rの円弧に近似するためのコントロールポイントの長さ

            x = MathF.Cos(a1) * c;
            y = MathF.Sin(a1) * c;
            var c1 = new Vector2(p1.X + x, p1.Y + y);

            x = MathF.Cos(a2) * c;
            y = MathF.Sin(a2) * c;
            var c2 = new Vector2(p2.X - x, p2.Y - y);

            //
            points[0] = c1;
            points[1] = c2;
            points[2] = p2;

            pb2 = p1;
            pn2 = p2;



            //            this.points[0] = p1;

            CmUtils.DebugWriteLine(string.Format("a1:{0:0.00},a2:{1:0.00},ac:{2:0.00},r:{3:0.00}", CmUtils.ToAngle(a1), CmUtils.ToAngle(a2), CmUtils.ToAngle(ac2), r));

            return(true);
        }
Exemplo n.º 4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="pn"></param>
        /// <returns></returns>
        internal SvgPathItem CreateRoundCorner(Vector2 pn)
        {
            var pc = GetPoint();
            var pb = befor.GetPoint();

            var a1 = MathF.Atan2(pc.Y - pb.Y, pc.X - pb.X); //傾き
            var a2 = MathF.Atan2(pn.Y - pc.Y, pn.X - pc.X); //次の線の傾き
            var a  = (a1 + a2) / 2;

            a = MathF.Abs(a);
            if (a > MathF.PI)
            {
                a -= MathF.PI;
            }

            float r = 2;
            float v = 0;


            v = r / MathF.Tan(a);              // 半径r円の接点の頂点からの距離
            float l1 = CmUtils.Length(pb, pc); // 自分の線の長さ
            float l2 = CmUtils.Length(pc, pn); // 次の線の長さ

            if (l1 < v || l2 < v)
            {
                return(null);
            }


            var citem = new SvgPathItem('C', this);

            var x  = MathF.Cos(a1) * v;
            var y  = MathF.Sin(a1) * v;
            var p1 = new Vector2(pc.X - x, pc.Y - y);

            x = MathF.Cos(a2) * v;
            y = MathF.Sin(a2) * v;
            var p2 = new Vector2(pc.X + x, pc.Y + y);


            var c = r * 0.5522847f; // 半径rの円弧に近似するためのコントロールポイントの長さ

            x = MathF.Cos(a1) * c;
            y = MathF.Sin(a1) * c;
            var c1 = new Vector2(p1.X + x, p1.Y + y);

            x = MathF.Cos(a2) * c;
            y = MathF.Sin(a2) * c;
            var c2 = new Vector2(p2.X - x, p2.Y - y);

            var points = new List <Vector2>();

            points.Add(c1);
            points.Add(c2);
            points.Add(p2);
            citem.SetPoints(points);

            this.points[0] = p1;

            CmUtils.DebugWriteLine(string.Format("a1:{0:0.00},a2:{1:0.00},vl:{2:0.00},cl:{3:0.00}", CmUtils.ToAngle(a1), CmUtils.ToAngle(a2), v, c));

            return(citem);
        }