Skip to content
This repository was archived by the owner on Mar 30, 2019. It is now read-only.
This repository was archived by the owner on Mar 30, 2019. It is now read-only.

Collision.RayIntersectsRay treats Rays as lines #1077

@mludlum

Description

@mludlum

When finding the intersection point:

float s = dets / denominator;
float t = dett / denominator;

//The points of intersection.
Vector3 point1 = ray1.Position + (s * ray1.Direction);
Vector3 point2 = ray2.Position + (t * ray2.Direction);

both s and t should be non-negative numbers because rays have a starting point.

I had to add this code after computing s and t.

            if (s < 0 || t < 0)
            {
                point = Vector3.Zero;
                return false;
            }

Also, I added the else in this section when the Rays are parallel but not on top of each other:

            //Lines are parallel.
            if (MathUtil.IsZero(denominator))
            {
                //Lines are parallel and on top of each other.
                if (MathUtil.NearEqual(ray2.Position.X, ray1.Position.X) &&
                    MathUtil.NearEqual(ray2.Position.Y, ray1.Position.Y) &&
                    MathUtil.NearEqual(ray2.Position.Z, ray1.Position.Z))
                {
                    point = Vector3.Zero;
                    return true;
                }
                else
                {
                    point = Vector3.Zero;
                    return false;
                }
            }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions