So I have a problem I’m trying to solve, I have two points and an angle. One point is the apex of a pyramid and the other is the center point of the bottom face. The angle is the interior angle between opposite edges. I know the pyramid is going to have four other vertices, and that the line pointing from the apex to the center is orthogonal to the plane containing those points (i.e. it’s a right quadrilateral pyramid). I also know that all the sides are equal length (right square pyramid). From there, I’d like to find the 3D coordinates of any four valid vertices (I’m not picky).
If that’s too vague, the actual problem is that I’m doing some graphics. I have a light I’ve defined in an external file with its position vector, look-at vector, and FOV angle and I’m trying to render (a truncated length version of) its FOV pyramid programmatically for debugging purposes (since the position, lookAt, and FOV can change between executions I can’t hard-code it). The position vector is, of course, the apex, and the look at vector (which will be normalized to a unit vector so that the pyramid doesn’t take up the whole screen) is the center of the base of the pyramid. The FOV angle is the interior angle between opposite edges.
I think if I can figure out where it lies, I can do something with the plane containing the circle that contains all valid vertices, I but I’m not completely sure, the translation between planar coordinates and world-coordinates seem like it could get hairy. And even if that is the answer, I can’t quiiite work out how to get there (though I think I’m close, since I have the normal to the plane as well as one point on it already).
Sorry if I you made this clear and I didn’t understand, but are you able to find the coordinates of the vertices if you place the center point of the bottom face at the (x,y,z) origin, and the apex along the z-axis? Then the vertices are in the x-y plane and are pretty easy to find using some basic trig like: tan(angle/2) = opp/adj, etc. Once you do that, you can rotate your coordinate system back to wherever the pyramid actually is and how it is oriented. I’m guessing that your issue is how to do a general 3d coordinate transformation?
Yeah, that’s how I ended up solving it on paper (though it’s not implemented yet), I was hoping there was a way to solve it that avoided transform matrices, since I like to avoid CPU matrix operations when possible.
Now that I think about it, I may be able to get the GPU to do the operations. My plan was to calculate the vertices and then draw there, but now that I think about it (this wasn’t obvious to me before, being a newbie at graphics), I can probably use OpenGL to just draw the pyramid at the origin and then transform it.
If I under stand the problem correctly you have a pyramid with a square base ABCD and the (x,y,z) coordinates of its apex P, and the size angle APC that goes between opposite corners of the base up to the apex. You also know the center of the base Q.
Without loss of generality I’m going to assume that the base is on the x,y plane and the diagonals are on the x,y, and the center is at (0,0) axis so that the vertices of the base are A=(0,a,0), B=(a,0,0), C=(-a,0,0), D=(0,-a,0) with unknown a. For other values simple shifts and rotations should get you in this framework.
I’ll line up the equations but let you work out the algebra.
Step 1) for a given value of a, I can compute the lengths of the sides AP and PC.
Step 2) considering the triangle APC and using the law of cosines you can derive the length of the diagonal across the base (AC) in terms of the angle APC and the length of the sides AP an PC.
Step 3) Since we also know that the length of this base is 2a, we can combine steps 1 and 2 into a single equation in terms of a and then solve for a.
ETA: Re-reading this I missed that it was a right pyramid. The above solves for the general case.
The trick wasn’t getting the lengths, that takes two seconds. The trick was adding the lengths to the vertices correctly so that the result ended up on the correct plane. As I said above, I was trying to avoid using matrix operations to translate/rotate it to [0,0,0] unless I had to. Now that I figured out a way to speed the matrices up (GPU), I’ll do that.
Okay, I’ll be honest, I can’t figure out the sequence of transforms now. I’ve worked out that you can probably rotate it around two axes and then translate it such that the base at 0,0,0 where go where the original base should go, but I can’t get the rotation matrices especially to come out.