Пример #1
0
        /// <summary>
        /// 取两点所在直线上的指定长度的向量
        /// </summary>
        /// <param name="lineStart">线起点</param>
        /// <param name="lineEnd">线终点</param>
        /// <param name="length">向量长度</param>
        /// <returns></returns>
        private static VectorD GetVectorOnLineByLength(PointD lineStart, PointD lineEnd, double length)
        {
            double  scale     = length / lineStart.DistanceTo(lineEnd);
            VectorD vectorOld = lineEnd - lineStart;

            return(vectorOld.ScaleBy(scale));
        }
Пример #2
0
        public static PointD GetScalePointOnLine(PointD lineStart, PointD lineEnd, double scale)
        {
            VectorD vLine  = lineEnd - lineStart;
            PointD  result = lineStart + vLine.ScaleBy(scale);

            return(result);
        }
Пример #3
0
        /// <summary>
        /// 以半径为基准作为获取过渡圆弧
        /// </summary>
        /// <param name="lineStart">线起点</param>
        /// <param name="intersection">线与原始圆弧交点</param>
        /// <param name="oriArcCenter">原始圆弧圆心</param>
        /// <param name="transitionR">过渡圆弧半径</param>
        /// <param name="oriArcClockwise">原始圆弧方向</param>
        /// <returns>过渡圆弧的起点、圆心、终点</returns>
        public static List <PointD> GetLineToArcTransitionArcByR(PointD lineStart, PointD intersection, PointD oriArcCenter, double transitionR, double oriArcClockwise)
        {
            List <PointD> points = new List <PointD>();
            PointD        transitionArcCenter, newLineEnd, newArcStart;
            double        angle = GetAngleOfTwoLine(lineStart, intersection, oriArcCenter);
            VectorD       vArcS = intersection - oriArcCenter;
            double        oriR  = vArcS.Length;
            VectorD       vArcSRotate1;

            if (oriArcClockwise == 1)
            {
                vArcSRotate1 = vArcS.Rotate(-90);
            }
            else
            {
                vArcSRotate1 = vArcS.Rotate(90);
            }

            if (angle != Math.PI)
            {
                //求原始圆弧半径
                double len1;
                if (GetAngleOfTwoLine(lineStart, intersection, (intersection + vArcSRotate1)) > (Math.PI / 2))
                {
                    len1 = oriR * Math.Sin(Math.PI - angle) + transitionR;
                }
                else
                {
                    len1 = oriR * Math.Sin(Math.PI - angle) - transitionR;
                }
                double  len2      = Math.Sqrt((oriR + transitionR) * (oriR + transitionR) - len1 * len1);
                PointD  footPoint = MathUtils.GetFootPoint(oriArcCenter, lineStart, intersection);
                VectorD vLenTemp  = (footPoint - oriArcCenter);
                VectorD vLen1     = vLenTemp.ScaleBy(len1 / vLenTemp.Length);
                VectorD vLine     = lineStart - intersection;
                VectorD vLen2     = vLine.ScaleBy(len2 / vLine.Length);
                transitionArcCenter = oriArcCenter + vLen1 + vLen2;
                newLineEnd          = MathUtils.GetFootPoint(transitionArcCenter, lineStart, intersection);
                newArcStart         = transitionArcCenter + (oriArcCenter - transitionArcCenter).ScaleBy(transitionR / (oriR + transitionR));
            }
            else
            {
                double  len1  = transitionR;
                double  len2  = Math.Sqrt((oriR + transitionR) * (oriR + transitionR) - len1 * len1);
                VectorD vLen2 = vArcS.ScaleBy(len2 / oriR);
                newLineEnd = oriArcCenter + vLen2;
                VectorD vLen1 = vArcSRotate1.ScaleBy(transitionR / vArcSRotate1.Length);
                transitionArcCenter = newLineEnd + vLen1;
                newArcStart         = transitionArcCenter + (oriArcCenter - transitionArcCenter).ScaleBy(transitionR / (transitionR + oriR));
            }
            points.Add(newLineEnd);
            points.Add(transitionArcCenter);
            points.Add(newArcStart);
            return(points);
        }
Пример #4
0
        /// <summary>
        /// 获取角平分线上一点
        /// </summary>
        /// <param name="start"></param>
        /// <param name="middle"></param>
        /// <param name="end"></param>
        /// <returns></returns>
        private static PointD GetAPointOnAngleBiscetor(PointD start, PointD middle, PointD end)
        {
            double len1  = start.DistanceTo(middle);
            double len2  = middle.DistanceTo(end);
            double scale = len1 / (len1 + len2);

            // 角平分线与对边交点
            PointD  point1  = new PointD();
            VectorD vector1 = end - start;

            point1 = start + vector1.ScaleBy(scale);
            return(point1);
        }
Пример #5
0
        /// <summary>
        /// 返回两线段交点 (实际情况不需要考虑不相交情况)
        /// </summary>
        /// <param name="line1Start">线1起点</param>
        /// <param name="line1End">线1终点</param>
        /// <param name="line2Start">线2起点</param>
        /// <param name="line2End">线2终点</param>
        /// <returns></returns>
        private static PointD GetIntersection(PointD line1Start, PointD line1End, PointD line2Start, PointD line2End)
        {
            double x1 = line1Start.X;
            double y1 = line1Start.Y;
            double x2 = line1End.X;
            double y2 = line1End.Y;
            double x3 = line2Start.X;
            double y3 = line2Start.Y;
            double x4 = line2End.X;
            double y4 = line2End.Y;

            double  t      = ((x2 - x1) * (y3 - y1) - (x3 - x1) * (y2 - y1)) / ((x2 - x1) * (y3 - y4) - (x3 - x4) * (y2 - y1));
            VectorD temp   = line2End - line2Start;
            PointD  result = line2Start + temp.ScaleBy(t);

            return(result);
        }