WPF 3D - converting from Point2D to Point3D and back again

Posted by DanM on Stack Overflow See other posts from Stack Overflow or by DanM
Published on 2010-04-29T19:30:04Z Indexed on 2010/04/29 21:37 UTC
Read the original article Hit count: 1309

Filed under:
|
|
|
|

I'm new to WPF 3D, so I may just be missing something obvious, but how would I go about converting from a 2D coordinate to a 3D coordinate and back again?

I'd like the 2D coordinate to be the location measured from the upper-left corner of Viewport3D and the 3D coordinate to be the location relative to the origin (0, 0, 0) of the 3D world.

The conversion functions should have these signatures:

public Point3D Point2DAndWorldZToPoint3D(Point2D point2D, double worldZ)
// usually I want to know where a 2D point will be on the ground plane
// so worldZ will usually be zero (but not always)

public Point2D Point3DToPoint2D(Point3D point3D)

I found this related question, but it only addresses conversion from 3D to 2D (not the reverse), and I'm not sure if the answers are up-to-date.

Note, I'm currently using .NET 3.5, but if there are improvements in .NET 4.0 that would help me, please let me know.

© Stack Overflow or respective owner

Related posts about wpf

Related posts about wpf-3d