0

I want to know if a ray from an arbitrary point will strike a polygon. It would be useful to know the point in space that intersection occurs and also a reference to that polygon. I'm using the System.Windows.Media.Media3D library and have done a ray trace test but have yet to crack any of teh information i want out of the HitTestResult object returned by VisualTreeHelper.HitTest.

Am i looking in the wrong place?

Is there a different approach to test for arbitrary intersection?

The Codez:

private void MainViewport_MouseRightButtonDown(object sender, MouseButtonEventArgs e)
{
    // Retrieve the coordinate of the mouse position.
    Point pt = e.GetPosition((UIElement)sender);

    // Perform the hit test against a given portion of the visual object tree.
    HitTestResult result = VisualTreeHelper.HitTest(MainViewport, pt);

    if (result != null)
    {
        // Perform action on hit visual object.
    }
}

2 Answers 2

2

I don't know the System.Windows.Media.Media3D, but:

  1. I guess you should create the ray direction by constructing a vector from the "eye coordinate" to the mouse-coordinate on the view-plane
  2. If the polygon is planar, you could solve for the intersection of the plane and the ray to get the hit-coordinate in that plane, then figure out if that point is within the polygon

A little vague response I know, but I hope it will be helpfull to you anyways.

Sign up to request clarification or add additional context in comments.

Comments

0

Can you downcast the HitTestResult to a RayHitTestResult? Does that have the information you need?

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.