Пример #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="LineIntersection"/> structure with the
        /// specified shared coordinates, relative locations, and spatial relationship between the
        /// intersected lines.</summary>
        /// <param name="shared">
        /// The <see cref="PointD"/> coordinates shared by the two line segments or their infinite
        /// extensions.</param>
        /// <param name="first">
        /// The location of the <see cref="Shared"/> coordinates relative to the first line segment.
        /// </param>
        /// <param name="second">
        /// The location of the <see cref="Shared"/> coordinates relative to the second line
        /// segment.</param>
        /// <param name="relation">
        /// The spatial relationship between the two line segments.</param>

        public LineIntersection(PointD?shared,
                                LineLocation first, LineLocation second, LineRelation relation)
        {
            Shared   = shared;
            First    = first;
            Second   = second;
            Relation = relation;
        }
Пример #2
0
 void OnTriggerStay(Collider other)
 {
     if (other.gameObject.tag == "LineDrawer")
     {
         LineRelation lineRelation = LineRelation.FindRelation(gameObject, other.gameObject);
         if (lineRelation != null)
         {
             lineRelation.lineRenderer.SetPosition(0, transform.position);
             lineRelation.lineRenderer.SetPosition(1, other.gameObject.transform.position);
         }
     }
 }
Пример #3
0
 void OnTriggerExit(Collider other)
 {
     if (other.gameObject.tag == "LineDrawer")
     {
         LineRelation lineRelation = LineRelation.FindRelation(gameObject, other.gameObject);
         if (lineRelation != null)
         {
             LineRenderer lineRenderer = lineRelation.lineRenderer;
             lineRelationList.Remove(lineRelation);
             Destroy(lineRenderer.gameObject);
         }
     }
 }
Пример #4
0
 void OnTriggerEnter(Collider other)
 {
     if (other.gameObject.tag == "LineDrawer")
     {
         if (LineRelation.FindRelation(gameObject, other.gameObject) == null)
         {
             GameObject newLineRendererObject = Instantiate <GameObject>(lineRendrerPrefab);
             newLineRendererObject.transform.SetParent(gameObject.transform);
             newLineRendererObject.transform.position = gameObject.transform.position;
             LineRenderer newLineRenderer = newLineRendererObject.GetComponent <LineRenderer>();
             newLineRenderer.SetPosition(0, transform.position);
             newLineRenderer.SetPosition(1, other.gameObject.transform.position);
             lineRelationList.Add(new LineRelation(gameObject, other.gameObject, newLineRenderer));
         }
     }
 }
Пример #5
0
        public static LineRelation FindRelation(GameObject obj1, GameObject obj2)
        {
            LineRelation res   = null;
            bool         found = false;
            int          i     = 0;

            while (!found && i < lineRelationList.Count)
            {
                if (lineRelationList[i].TestEqual(obj1, obj2))
                {
                    res   = lineRelationList[i];
                    found = true;
                }
                i++;
            }
            return(res);
        }
Пример #6
0
        /// <summary>
        /// 与线的关系
        /// </summary>
        /// <param name="line"></param>
        /// <returns></returns>
        public override LineRelation CheckLineRelation(Line3D line)
        {
            LineRelation lr = base.CheckLineRelation(line);

            if (lr == LineRelation.Intersect)
            {
                Double3 aixsVector = line.AixsVector(this.StartPoint);
                if (Double3.Dot(aixsVector, this.NormalizedDir) > 0)
                {
                    return(LineRelation.Detach);
                }
                else
                {
                    return(LineRelation.Intersect);
                }
            }
            else
            {
                return(lr);
            }
        }
Пример #7
0
        /// <summary>
        /// 与线的关系
        /// </summary>
        /// <param name="line"></param>
        /// <returns></returns>
        public override LineRelation CheckLineRelation(Line3D line)
        {
            LineRelation lr = base.CheckLineRelation(line);

            if (lr == LineRelation.Intersect)
            {
                // 计算轴向量
                Double3 aixsVector1 = line.AixsVector(this.StartPoint);
                Double3 aixsVector2 = line.AixsVector(this.EndPoint);
                // 方向相反相交
                if (Double3.Dot(aixsVector1, aixsVector2) <= 0)
                {
                    return(LineRelation.Intersect);
                }
                else
                {
                    return(LineRelation.Detach);
                }
            }
            else
            {
                return(lr);
            }
        }
Пример #8
0
        /// <overloads>
        /// Initializes a new instance of the <see cref="LineIntersection"/> structure.</overloads>
        /// <summary>
        /// Initializes a new instance of the <see cref="LineIntersection"/> structure with the
        /// specified spatial relationship between the intersected lines.</summary>
        /// <param name="relation">
        /// The spatial relationship between the two line segments.</param>
        /// <remarks>
        /// The <see cref="First"/>, <see cref="Second"/>, and <see cref="Shared"/> properties
        /// remain at their default values. Use this constructor for collinear or parallel line
        /// segments that share no points.</remarks>

        public LineIntersection(LineRelation relation) : this(null, 0, 0, relation)
        {
        }