I have a 3d point, defined by [x0, y0, z0]
.
This point belongs to a plane, defined by [a, b, c, d]
.
normal
= [a, b, c]
, and ax + by + cz + d = 0
How can convert or map the 3d point to a pair of (u,v)
coordinates ?
This must be something really simple, but I can't figure it out.
First of all, you need to compute your u
and v
vectors. u
and v
shall be orthogonal to the normal of your plane, and orthogonal to each other. There is no unique way to define them, but a convenient and fast way may be something like this:
n = [a, b, c]
u = normalize([b, -a, 0]) // Assuming that a != 0 and b != 0, otherwise use c.
v = cross(n, u) // If n was normalized, v is already normalized. Otherwise normalize it.
Now a simple dot product will do:
u_coord = dot(u,[x0 y0 z0])
v_coord = dot(v,[x0 y0 z0])
Notice that this assumes that the origin of the u-v coordinates is the world origin (0,0,0).
This will work even if your vector [x0 y0 z0]
does not lie exactly on the plane. If that is the case, it will just project it to the plane.
Assuming you want to find the coordinates of any point in the plane, in terms of coordinates (u,v)...
If the point [x0,y0,z0] lies in the plane, then we know that
dot([a,b,c],[x0,y0,z0]) = -d
Where dot is the dot product between two vectors. This is simply rewriting the plane equation.
The trick is to find two vectors that span the planar subspace. To do this, we choose a random vector of length 3. Call it V0. I'll call the planar normal vector
N = [a,b,c]
Next, use the cross product of the normal vector N with V0.
V1 = cross(N,V0)
This vector will be orthogonal to the normal vector, unless we were extremely unlucky and N and V0 were collinear. In that case, simply choose another random vector V0. We can tell if the two vectors were collinear, because then V1 will be the vector [0 0 0].
So, if V1 is not the zero vector, then divide each element by the norm of V1. The norm of a vector is simply the square root of the sum of the squares of the elements.
V1 = V1/norm(V1)
Next, we choose a second vector V2 that is orthogonal to both N and V1. Again, a vector cross product does this trivially. Normalize that vector to have unit length also. (Since we know now that V1 is a vector with unit norm, we could just have divided by norm(N).)
V2 = cross(N,V1)
V2 = V2/norm(V2)
ANY point in the plane can now be described trivially as a function of (u,v), as:
[x0,y0,z0] + u*V1 + v*V2
For example, when (u,v) = (0,0), clearly we get [x0,y0,z0] back, so we can think of that point as the "origin" in (u,v) coordinates.
Likewise, we can do things like recover u and v from any point [x,y,z] that is known to lie in the plane, or we can find the normal projection for a point that is not in the plane, projected into that plane.
来源:https://stackoverflow.com/questions/18663755/how-to-convert-a-3d-point-on-a-plane-to-uv-coordinates