示例#1
0
        /// <summary>
        /// 根据圆外一点计算圆弧切点
        /// </summary>
        /// <param name="outPoint"></param>
        /// <param name="turnDirection"></param>
        /// <returns></returns>
        public Point3D GetTangentPointbyOutPoint(Point3D outPoint, TurnDirectionType turnDirection)
        {
            //List<Point3D> list = GetIntersectPointsWithLine(outPoint, this.Center);
            //if (list == null || list.Count <= 0)
            //{
            //    return null;
            //}

            double outPointToCenterDistance = Center.DisTo(outPoint);

            if (Math.Abs(outPointToCenterDistance - Radius) < OverrallVraTool.DoublePrecision) //近似相等
            {
                return(outPoint);
            }

            if (outPointToCenterDistance < Radius) //点在圆内无切点
            {
                return(null);
            }

            double pointToTangentPointDistance = Math.Sqrt(Math.Pow(outPointToCenterDistance, 2) - Math.Pow(Radius, 2));
            double tangentLineDirection        = Center.DirTo(outPoint)
                                                 + Math.Atan(pointToTangentPointDistance / Radius)
                                                 * (turnDirection == TurnDirectionType.Left ? 1 : -1);

            Point3D p = Center.GetNextPoint(tangentLineDirection, Radius);

            if (this.GetRelationShipWithPoint(p) == PointArcRelationShipType.On_ArcSegment)
            {
                return(p);
            }
            return(null);
        }
示例#2
0
        /// <summary>
        /// 计算传入的射线和当前圆弧位置关系
        /// </summary>
        /// <param name="line">传入的射线</param>
        /// <returns></returns>
        public override LineCurveRelationShipType GetCurveCurveRelationShipType(LineSegment line)
        {
            LineArcRelationShipType type = GetRelationShipwithLine(line);
            var dir = line.GetTurnDirection(this.Center);

            if (type == LineArcRelationShipType.Apart) //相离
            {
                if (dir == TurnDirectionType.Left)
                {
                    return(LineCurveRelationShipType.Left);
                }
                else
                {
                    return(LineCurveRelationShipType.Right);
                }
            }
            else if (type == LineArcRelationShipType.Insert) //和圆弧相交
            {
                if (this.BeginPoint.Equals(this.EndPoint))
                {
                    return(LineCurveRelationShipType.Intersect);
                }
                else
                {
                    //1.半圆情况下,可能begin,end点为交点,则onleft或onright

                    /*
                     * (1)过begin,end点做直线
                     * (2)过直线中心做垂线,交圆弧于点p
                     * (3)判断点p和直线的位置关系
                     */
                    //2.交点存在非begin,end点,则为intersect
                    TurnDirectionType dirB = line.GetTurnDirection(this.BeginPoint);
                    TurnDirectionType dirE = line.GetTurnDirection(this.EndPoint);
                    if (dirB == TurnDirectionType.Stright && dirE == TurnDirectionType.Stright)
                    {
                        Point3D lineCenterPoint = new Point3D()
                        {
                            X = (this.BeginPoint.X + this.EndPoint.X) / 2, Y = (this.BeginPoint.Y + this.EndPoint.Y) / 2, Z = (this.BeginPoint.Z + this.EndPoint.Z) / 2
                        };

                        LineSegment    centerLine = new LineSegment(lineCenterPoint, 1, line.GetDirection() + Math.PI / 2);
                        List <Point3D> listPoint  = this.GetIntersectPointsWithLine(centerLine.BeginPoint, centerLine.EndPoint);
                        if (listPoint != null && listPoint.Count > 0)
                        {
                            if (line.GetTurnDirection(listPoint[0]) == TurnDirectionType.Right)
                            {
                                return(LineCurveRelationShipType.On_Right);
                            }
                            else if (line.GetTurnDirection(listPoint[0]) == TurnDirectionType.Left)
                            {
                                return(LineCurveRelationShipType.On_Left);
                            }
                        }
                    }
                    else
                    {
                        return(LineCurveRelationShipType.Intersect);
                    }
                }
            }
            else if (type == LineArcRelationShipType.InsertWithArc) //和圆弧所在的圆相交
            {
                if (this.BeginPoint.Equals(this.EndPoint))
                {
                }
                else
                {
                    //只有半圆存在该情况
                    if (line.GetTurnDirection(this.BeginPoint) == TurnDirectionType.Left)
                    {
                        return(LineCurveRelationShipType.Left);
                    }
                    else
                    {
                        return(LineCurveRelationShipType.Right);
                    }
                }
            }
            else if (type == LineArcRelationShipType.InsertWithArcSegmentAndArc) //和圆弧,圆弧所在的圆分别相交
            {
                if (this.BeginPoint.Equals(this.EndPoint))
                {
                }
                else
                {
                    //只有半圆存在该情况
                    TurnDirectionType dirB = line.GetTurnDirection(this.BeginPoint);
                    TurnDirectionType dirE = line.GetTurnDirection(this.EndPoint);

                    if ((dirB == TurnDirectionType.Right && dirE == TurnDirectionType.Left) ||
                        (dirB == TurnDirectionType.Left && dirE == TurnDirectionType.Right))
                    {
                        return(LineCurveRelationShipType.Intersect);
                    }
                    else if ((dirB == TurnDirectionType.Right && dirE == TurnDirectionType.Stright) ||
                             (dirB == TurnDirectionType.Stright && dirE == TurnDirectionType.Right))
                    {
                        return(LineCurveRelationShipType.On_Right);
                    }
                    else if ((dirB == TurnDirectionType.Left && dirE == TurnDirectionType.Stright) ||
                             (dirB == TurnDirectionType.Stright && dirE == TurnDirectionType.Left))
                    {
                        return(LineCurveRelationShipType.On_Left);
                    }
                }
            }
            else if (type == LineArcRelationShipType.Tangent) //和圆弧相切
            {
                if (dir == TurnDirectionType.Left)
                {
                    return(LineCurveRelationShipType.On_Left);
                }
                else
                {
                    return(LineCurveRelationShipType.On_Right);
                }
            }
            else if (type == LineArcRelationShipType.TangentWithArc) //和圆弧所在的圆相切
            {
                if (this.BeginPoint.Equals(this.EndPoint))
                {
                }
                else
                {
                    //只有半圆存在该情况
                    if (dir == TurnDirectionType.Left)
                    {
                        return(LineCurveRelationShipType.Left);
                    }
                    else
                    {
                        return(LineCurveRelationShipType.Right);
                    }
                }
            }
            return(LineCurveRelationShipType.Others);
        }