How do I know if a particular Point3D is within the scope of the camera view?

So what is it. I have a specific Point3D. I have a camera. I know the camera angle, which is 45 degrees; I know the position of the camera and the LookDirection vector. Now I want to find out if the dot will be visible to the camera or not.

So p1 Should be visible, p2 should not Thanks for those who answered and commented, but:

  • This is not an easy problem for me. This may seem like a simple thing, but I did not find a special method or helper class to solve the problem. I tried to solve it myself in a purely mathematical way, but the solution is unstable and works unpredictably:

    bool isPointInCameraView(Point3D P, Point3D CP, Vector3D LD, double CameraAngle) { //first calculate Distance to the plane formed by normal vector LD and point P on it var D = -LD.X*PX-LD.Y*PY-LD.Z*PZ; // -AXb-BYb-CZb //L is the distance to the plane. double L = Math.Abs( (LD.X * CP.X + LD.Y * CP.Y + LD.Z * CP.Z + D)) / Math.Sqrt(LD.X * LD.X + LD.Y * LD.Y+LD.Z * LD.Z); var BL = L * Math.Tan(CameraAngle); //length of bound part var PL = Math.Sqrt(((new Vector3D(PX - CP.X, PY - CP.Y, PZ - CP.Z)).LengthSquared - L * L)); // length of point part //test if point is out of bounds! return PL <= BL; } 
  • I know about Helix3D, and I use it. My viewport and camera are from the helix framework.

I think it will be easier to understand the problem if I explain the reason why I need such a test. I am creating a geophysical data visualization application, and I need to be able to bring the depth closer to the texture in order to see the details. The problem was that I could not use textures that were too large, since they took up too much memory and took too long to draw. Then I decided to divide my plane into several touch-ups, each of which should be handled separately. So the idea is that when the user approaches a certain part of the plane, I would only do this part. It worked fine, except that the code was still redrawing textures for those subpriklings that were invisible to the camera. Now I want to optimize this. I tried to find any special function that would allow me to do this, but failed. So while the solution is only mathematical and unstable, it does not work correctly. That is why I asked this question here.

+6
source share
1 answer

Nice picture!

I think this is not so simple if you do not have a camera in Viewport3D. You will need to combine Visual3D transforms with camera transforms.

The easiest way would be to put the material in Viewport3D. Then your question is similar to this one: Projecting a 3D point onto the coordinate of a 2D screen , and this one: Information about 3D projection .

Note that some of the answers were written before .NET 3.5, which added the Visual3D.TransformToAncestor helper function, which you probably need. Read more about TransformToAncestor here: http://blogs.msdn.com/b/wpf3d/archive/2009/05/13/transforming-bounds.aspx .

And if you are doing anything with WPF 3D, you need to know about the awesome Helix Toolkit , which is a replacement for 3DTools that contains presentation controls and various helpers and is actively being processed.

+1
source

Source: https://habr.com/ru/post/915643/


All Articles