views:

467

answers:

2

Hi there,

I have a planar element in 3D space that I've rotated on the x, y and z axis. I'm positioning a 3D camera in front of the planar but I need to find a way to calculate the x, y, z of the camera.

I'm trying to figure out how to place the camera at x distance from the planes face. There's obviously a bit of trig involved but for the life of me can't figure it out. Gah.

Dave

+1  A: 

The relation between distance of a point to a plane is

distance = (Aa + Bb + Cc + D) / sqrt(A^2+B^2+C^2)

for distance to plane Ax + By + Cz + D = 0 from point (a,b,c)

Might need to multiply by -1 to get distance positive.

The equations for the line through point (a,b,c) perpendicular to the same plane is

x = a + At; y = b + Bt; z = c + Ct

So if you have a point in the plane, you can find the equation of the line perpendicular to that plane. Then you can use the distance constraint to solve for two points a distance along that line - one above the plane, and one below.

John at CashCommons
Sorry, that's confused me dramatically. Excuse my ill-math skills but if you could simplify/clarify for me it would be helpful.Lets say the planar is at A (493, 543, 234) - these x, y, z values are referencing from the centre of the plane - and I want the camera positions at 500 units from that point. The planars rotation is x = 34, y = 54, z = 32.So I'd like to find out what point B (?, ?, ?) - the camera - is according to the planars rotation. My best guess was to triangulate a point from the planes four vertices (which I for this case will specify as being 400 width).
http://mathworld.wolfram.com/Plane.html
John at CashCommons
I don't understand. What is A? What is "the planar?" Are x, y, and z in degrees? What is the sense of the rotation? It sounds like you have a finite sheet, not a plane (which is infinite). Is this true?
John at CashCommons
Lets just follow this equation because it's making more sense than what I wrote in the above comment. If you can help me solve this John I'll award you the answer :-) Lets say my normal vector is N = (400, 500, 600) and my P = (405, 505, 605) I would then calculate my P' by doing this: Camera coords: x = Px + x * Nx y = Py + x * Ny z = Pz + x * Nz I'm I getting this right now? lol...or completely off?
OK, we have progress. :) The point in the plane is P = (Px,Py,Pz). Your normal vector needs to have magnitude 1, so divide each component of N by sqrt(400^2 + 500^2 + 600^2) which is about 877, so N = (Nx,Ny,Nz) is about (400/877, 500/877, 600/877). You said you wanted a distance 500 from this point. So then with P' = (Px',Py',Pz'), we have Px' = Px + 500*Nx, Py' = Py + 500*Ny, Pz' = Pz + 500*Nz. Make more sense?
John at CashCommons
Great, haha. Progress is always good.So I only need to add the magnitude to the normal vector not the secondary P value? I've coded it up and am getting very weird results. Either I need to debug it more closely or I'm getting the calculating wrong. I'll get back to you in the next 30 minutes.Thank you for your continued patience!
No - you're starting at P (a vector), and displacing 500 units in the direction of N (adding another vector) to arrive at P'. You add 500*N to P to arrive at P'. (I really wish I could boldface letters in comments. Would make this much easier.) If you're getting weird results, are you calculating N correctly? This is where understanding the math might come in. You need the x, y, and z components of the normal vector. These might just be the directon cosines, which relate to your angles (34,54,32) (if that's what those numbers are.)
John at CashCommons
Thanks, I'll give it a try on the weekend, I'm completely swamped with work. I see what you're saying now...ahhhhh.
+2  A: 

If you have a plane then you also have its normal vector N and some point on it P.
If you calculate P'=P+x*N you'll get the point P' which is x units infront of point P in the direction of the normal.

shoosh
Hmmmmm. Ok, interesting. Not understanding it 100%, refer to my comment for John W. for a better explanation of what I mean. I'm pretty sure in order to solve this the equation would need to factor in the rotation of the plane to make sure it's facing it correctly.
David, yes. Shoosh's answer is a vector equation. P', P, and N are vectors. x is a scalar. The unit vector's components are a direct result of the orientation of the plane.
John at CashCommons
Ok, but being the non-math-focused I am I need to understand how to code these values. The Wolfram article is very helpful in explaining the process, but the math is beyond me.So how could I produce an x, y, z to position the camera from that equation? My guess would be that I have to simply replace N with the vector value.
"being the non-math-focused" is not an excuse for lazyness. get some decent vector arithmetic book and figure out just exactly it is you want to do.
shoosh