views:

24

answers:

1

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.
    }
}
A: 

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.

S.C. Madsen