LineIntersect() public method

public LineIntersect ( LineSegment2D, l2, Vector2D, &res ) : bool
l2 LineSegment2D,
res Vector2D,
return bool
Ejemplo n.º 1
0
    public List <HitInfo> IntersectTriangle(Triangle triangle)
    {
        List <HitInfo> res = new List <HitInfo>();

        for (int i = 0; i < vertices.Count; i++)
        {
            LineSegment2D l1 = new LineSegment2D(V2(vertices[i]), V2(vertices[(i + 1) % vertices.Count]));

            for (int j = 0; j < 3; j++)
            {
                LineSegment2D l2 = new LineSegment2D(V2(triangle.Vertex(j)), V2(triangle.Vertex((j + 1) % 3)));
                Vector2D      point;
                if (l1.LineIntersect(l2, out point))
                {
                    double distance      = (point - V2(vertices[i])).magnitude;
                    double segmentLength = l1.Length();
                    //if (l1.DoLinesIntersect(l2)){
                    double   normalizedDistance = distance / segmentLength;
                    Vector3D point3D            = Vector3D.Lerp(new Vector3D(vertices[i]), new Vector3D(vertices[(i + 1) % vertices.Count]), normalizedDistance);
                    res.Add(new HitInfo(i, j, point3D.ToVector3()));
                }

                /*Vector2 intersectionPoint;
                 * if (LineLineIntersection(from,to, tFrom, tTo,out intersectionPoint)){
                 *      float normalizedDistance = Vector3.Dot(to-from, tTo-tFrom);
                 *      Vector3 point3D = Vector3.Lerp (vertices[i], vertices[(i+1)%vertices.Count], normalizedDistance);
                 *      res.Add(new HitInfo(i,j,point3D));
                 * }*/
            }
        }
        return(res);
    }
Ejemplo n.º 2
0
 public bool IsIntersecting(LineSegment2D ls)
 {
     foreach (var l in GetLineSegments())
     {
         Vector2D p = new Vector2D();
         if (ls.LineIntersect(l, out p))
         {
             return(true);
         }
     }
     return(false);
 }
Ejemplo n.º 3
0
 public bool IsIntersecting(LineSegment2D ls, out Vector2D p)
 {
     foreach (var l in GetLineSegments())
     {
         if (ls.LineIntersect(l, out p))
         {
             return(true);
         }
     }
     p = Vector2D.zero;
     return(false);
 }
Ejemplo n.º 4
0
 public bool IsIntersecting(LineSegment2D ls)
 {
     foreach (var l in GetLineSegments()){
         Vector2D p = new Vector2D ();
         if (ls.LineIntersect(l, out p)) {
             return true;
         }
     }
     return false;
 }
Ejemplo n.º 5
0
    public List<HitInfo> IntersectTriangle(Triangle triangle)
    {
        List<HitInfo> res = new List<HitInfo>();
        for (int i=0;i<vertices.Count;i++){
            LineSegment2D l1 = new LineSegment2D(V2(vertices[i]), V2(vertices[(i+1)%vertices.Count]));

            for (int j=0;j<3;j++){
                LineSegment2D l2 = new LineSegment2D(V2(triangle.Vertex(j)), V2(triangle.Vertex((j+1)%3)));
                Vector2D point;
                if (l1.LineIntersect(l2, out point)){
                    double distance = (point - V2(vertices[i])).magnitude;
                    double segmentLength = l1.Length();
                //if (l1.DoLinesIntersect(l2)){
                    double normalizedDistance = distance/segmentLength;
                    Vector3D point3D = Vector3D.Lerp (new Vector3D (vertices[i]), new Vector3D (vertices[(i+1)%vertices.Count]), normalizedDistance);
                    res.Add(new HitInfo(i,j,point3D.ToVector3()));
                }
                /*Vector2 intersectionPoint;
                if (LineLineIntersection(from,to, tFrom, tTo,out intersectionPoint)){
                    float normalizedDistance = Vector3.Dot(to-from, tTo-tFrom);
                    Vector3 point3D = Vector3.Lerp (vertices[i], vertices[(i+1)%vertices.Count], normalizedDistance);
                    res.Add(new HitInfo(i,j,point3D));
                }*/
            }
        }
        return res;
    }
Ejemplo n.º 6
0
 public bool IsIntersecting(LineSegment2D ls, out Vector2D p)
 {
     foreach (var l in GetLineSegments()){
         if (ls.LineIntersect(l, out p)) {
             return true;
         }
     }
     p = Vector2D.zero;
     return false;
 }