# Coordinates of camera bounding box projected on another object.

I hope i am posting this in correct forum.

I am preprocessing a DEM to split and will later be loaded into a 3D modeling program. Due to the large size, this all must be done before loading into the program.

I have a series of points in 3D Cartesian coordinates. Each point also has rotation values of the camera. So i know the position in 3D space of the camera and the direction it is pointing.

What I am trying to do is calculate the coordinates of the bounding box corners of the rectangle that is projected onto the surface.

What is proving to be problematic for me is that i only know limited information in the problem.

In the below image(sorry for my terrible artwork) I know the following information
P = (x, y, z)
R = (x, y, 0)
S = simple geometry

Camera Settings: For the purposes of this question we will assume the following
1) Camera Orientation is at a -45 degree angle from the plane point P is on
2) Focal Length is 44mm
3) Field of View is 40 degrees
4) Sensor Size is 32mm
5) Aspect Ratio is 16:9

If it simplifies things. We can assume that point P is the beginning of the rays PA, PB, PC, and PD.

I need to find the coordinates for A, B, C, D.

Note: The cube does not exist. It just helps frame the problem

Picture showing what I am doing

Possible/Not Enough Information. I am continuing to work on filling in more data to hopefully simplify the problem.

## Update:

I updated the picture with some additional information. The blue triangles are what is shown in this second picture

Section from previous picture

I am trying to tackle this by finding the center of the projection.

To do so I am using a 45 degree angle of the camera from the Plane containing point P.

The point PW is a ray from the center of the camera to the center of projection.

This gives me the distance to the point from both point R and point P.

Where I am stuck now is visible in the second picture.
On the red triangle, I only know the hypotenuse and point R. I feel like I am overlooking something simple here to get coordinates of point W.

• What do you know about the four rays $PA$, $PB$, $PC$, $PD$ other than the point $P$? Jan 18, 2018 at 20:04
• Camera details. I haven't defined them yet. But I will know the view angles of the camera and any other related data Jan 18, 2018 at 20:08
• Oh. I forgot to add this to picture. I know the orientation of the camera. So I know the angle of the camera from the plane P is on, that is parallel to the surface RS Jan 18, 2018 at 20:11
• In your first picture, that little rectangle up near $P$ that defines what the camera actually sees? That is the information needed. Specifically: How far is that rectangle from the point $P$, what are the side lengths of that rectangle, and how is that rectangle oriented. With that information, you can solve this. Without that information, the problem isn't well-defined and cannot be solved. Jan 19, 2018 at 1:45
• OK. Thank you. I will define those properties and update question. Jan 19, 2018 at 1:47

Those are specifications for a physical camera, not a virtual one. The common virtual camera is just a point (the "camera") and nearby rectangle (the "view") that represents the picture you are taking. It has no "sensor", and unless you are going for special affects, it has no need to focus. The picture is defined by drawing rays from the camera through points (pixels) in the view until they reach an object, whose illumination then defines the pixel value. (I should note that I have never dealt with 3D shading, so I can't advise you on illumination. All I've done is frameworks.) The camera is defined by the following quantities:

• Aspect ratio - the ratio $R_A$ of height to width of the view.
• Angle-of-view (a.k.a. field-of-view) - An angular measure of the size of the view. Unfortunately, there are 3 different measures that get called this: the height, width, or diagonal lengths. Since you didn't say which you were referring to, I don't know which of these is supposed to be $40^\circ$. I will use $\alpha_h$ to be half the angular height, and $\alpha_w$ to be half the angular width. (I want them to be the half vaues to avoid having to divide by two every time I use them in a formula.) They are related by $\sin {\alpha_h} = R_A\sin \alpha_w$.
• Camera location $P$ with coordinates $(x_P, y_P, z_P)$.
• Camera Direction - a unit vector pointing from the camera location to the center of the view. The "view-plane" (the plane that the view lies in) is perpendicular to the camera direction. It can be specified by longitude $\theta$ and latitude $\phi$.
• Camera Orientation - the angle $\psi$ in the plane of the field-of-view between the "right-hand" direction of the picture and some reference direction, increasing in the counter-clockwise direction as seen from the camera. For the reference direction we can use the cross-product of the camera direction and the positive $z$-axis. (This breaks down when $\phi = 0$ or $\pi$. If this is an issue for you, we can discuss how to deal with it.)

Since the view is defined by angular measurements, you get the same picture no matter how close or far the view is from the camera location. So we put it at a distance of $1$. To project the view onto your landscape, you need to find its four corners. Since you seem to be concerned about the center, we can find that as well. Graphics calculations are usually done using quaternions, but I've never use quaternions enough to remember how they are used from one time to the next, so I and going to use vectors instead.

First we find the camera direction vector $\hat n$: $$\hat n = \begin{bmatrix}\cos \phi\cos \theta\\ \cos \phi\sin \theta\\ \sin \phi\end{bmatrix}$$ This vector has length one, and we are placing the view at a distance of $1$ from the camera, so the center of the view will be at $$V_C = P + \hat n = \begin{bmatrix}x_P + \cos \phi\cos \theta\\ y_P + \cos\phi\sin \theta\\z_P + \sin \phi\end{bmatrix}$$ To find the orientation of the view, we first need a coordinate system in the view-plane. if $\hat k = (0,0,1)$ is the positive $z$-axis, then the base-right-hand direction is $\hat r = \dfrac {\hat n \times \hat k}{\|\hat n \times \hat k\|}$ (we divide by the norm to get a unit vector again). This is: $$\hat r = \begin{bmatrix}\sin \theta\\-\cos \theta\\0\end{bmatrix}$$For the base-up direction, use $$\hat u = \hat r \times \hat n = \begin{bmatrix}-\sin \phi\cos \theta\\ \sin\phi\sin\theta\\\sin^2 \theta - \cos^2 \theta\end{bmatrix}$$ But our directions are rotated from this orientation by $\psi$: $$\hat w = \hat r\cos \psi + \hat u\sin \psi \\\hat h = -\hat r\sin \psi + \hat u\cos \psi$$ (At this stage, the coordinates cease simplifying to something nicer than is found by direct calculation, so I will stop giving coordinate representations.) Note that in exact mathematics, these later calculations are guaranteed to give unit vectors. However, computers are not capable of doing math to infinite precision. Depending on how much accuracy you need, you may want to divide $\hat h$ and $\hat w$ by their norms to insure they are as close to unit vectors as you can get. Now the distance from the center of the view to its right-hand edge is $\sin \alpha_w$ and the distance to the top of the view is $\sin \alpha_h$. So the four corners of the view are going to be given by $$V_{RT} = V_C + \hat w\sin \alpha_w + \hat h\sin \alpha_h\\ V_{LT} = V_C - \hat w\sin \alpha_w + \hat h\sin \alpha_h\\ V_{RB} = V_C + \hat w\sin \alpha_w - \hat h\sin \alpha_h\\ V_{LB} = V_C - \hat w\sin \alpha_w - \hat h\sin \alpha_h$$

The five rays from $P$ through these points are given by $$P + t(V_C - P)\\P + t(V_{RT} - P)\\P + t(V_{LT} - P)\\P + t(V_{RB} - P)\\P + t(V_{LB} - P)$$ for values of $t \ge 0$.

To find the corners of your bounding box, it looks like you are after where the rays through $V_{RT}, V_{LT}, V_{RB}, V_{LB}$ intersect the plane $z = 0$. For example, to find the upper-right corner, labeling $V_{RT} = (x_{RT}, y_{RT}, z_{RT})$, the points on this ray have the form $$(x_P + t(x_{RT} - x_P), y_P + t(y_{RT} - y_P), z_P + t(z_{RT} - z_P))$$ You want where it crosses $z = 0$, so $z_P + t(z_{RT} - z_P)) = 0$, which give $$t = -\frac{z_P}{z_{RT}-z_P}$$Plugging this back into the ray equation, the upper right-hand corner is given by $$\left(x_p + z_P\frac{x_{RT} - x_P}{z_{RT} - z_P}, y_p + z_P\frac{y_{RT} - y_P}{z_{RT} - z_P}, 0\right)$$

• Thank you for this explanation. The camera values i grabbed out of a scene I setup in the program Blender. This looks like it is exactly what i am looking for. I will work it out with some test data to verify. Jan 20, 2018 at 19:58
• For Camera Direction you said "It can be specified by longitude θ θ and latitude ϕ ϕ " I don't fully understand what you mean by that. I am using pitch, heading, roll for camera orientation. So 0,0,0 looks north, with up to the sky. Jan 22, 2018 at 18:15
• Since you didn't specify how you were measuring the camera orientation, I had to choose a system. However, pitch, heading, and roll are just other names for latitude ($\phi$), longitude ($\theta$) and orientation ($\psi$) as I've defined them. If you have $(0,0,0)$ pointing up, then you are not using the normal meaning of pitch, which is the angle the principle axis of the objects makes with the horizontal plane. If you can define or link to the camera angles you are using, then I can figure out how to change this to match them. Jan 23, 2018 at 0:38
• I realized I didn't add that detail when i was reading your answer. The camera values i am receiving are coming from cesium(cesiumjs.org/Cesium/Build/Documentation/Camera.html). Just to clarify... (0,0,0) has a heading looking due North, with a pitch looking at the horizon. The up direction on the camera is to the sky. Jan 23, 2018 at 1:07
• Okay - that makes sense, except "North" is not a defined direction in your virtual space. The defined directions are "postive x", "positive y", "positive z", and of couse their opposites. "Up" most commonly means "positive z" (though there are certain special situations where negative z is the choice). But the compass directions have no such almost universal relationship. Jan 23, 2018 at 2:59