0
votes

I have a defined plane (one which happens to be orthogonal to the vector defined by two xyz points in 3D space). I can project any xyz point onto the plane and represent that projection uv coordinate space. I would like to take an arbitrary point in uv coordinate space and find out what its coordinates are in xyz space.

a = x2 - x1
b = y2 - y1
c = z2 - z1
d = -1*(a*x1 + b*y1 + c*z1)
magnitude = (a**2 + b**2 + c**2)**.5
u_magnitude = (b**2 + a**2)**.5

normal = [a/magnitude, b/magnitude, c/magnitude]
u = [b/u_magnitude, -a/u_magnitude, 0]
v = np.cross(normal, u)

p_u = np.dot(u,[x1,y1,z1])
p_v = np.dot(v,[x1,y1,z1])

This code I believe accurately produces the plane I want and will assign the x1,y1,z1 point in uv coordinates to p_u,p_v. My sense is that I have everything I need to do the reverse operation, but I don't know how. If I have a point u0,v0 how can I find x0,y0,z0 that describes its location in 3D space?

1
How would you find a unique pair of axes in the plane for any arbitrary normal direction?meowgoesthedog

1 Answers

1
votes

From the definition in the text (not reading the code), the problem is not well defined - as there is an infinite number of planes orthogonal to a given vector (think of all the options as planes at different "offsets" along the line from the first point to the second). What you need is first to pick some point through which the plane has to go.

Secondly, when we convert a (U, V) pair to 3D point, I assume you mean a 3D point on the plane.

Trying to be more concrete though, here is your code, with documentation on how I understand it, and how to do the reverse:

# ### The original computation of the plane equation ###
# Given points p1 and p2, the vector through them is W = (p2 - p1)
# We want the plane equation Ax + By + Cz + d = 0, and to make
# the plane prepandicular to the vector, we set (A, B, C) = W
p1 = np.array([x1, y1, z1])
p2 = np.array([x2, y2, z2])

A, B, C = W = p2 - p1

# Now we can solve D in the plane equation. This solution assumes that
# the plane goes through p1.
D = -1 * np.dot(W, p1)

# ### Normalizing W ###
magnitude = np.linalg.norm(W)
normal = W / magnitude

# Now that we have the plane, we want to define
# three things:
# 1. The reference point in the plane (the "origin"). Given the
#    above computation of D, that is p1.
# 2. The vectors U and V that are prepandicular to W
#    (and therefore spanning the plane)

# We take a vector U that we know that is perpendicular to
# W, but we also need to make sure it's not zero.
if A != 0:
    u_not_normalized = np.array([B, -A, 0])
else:
    # If A is 0, then either B or C have to be nonzero
    u_not_normalized = np.array([0, B, -C])
u_magnitude = np.linalg.norm(u_not_normalized)

# ### Normalizing W ###
U = u_not_normalized / u_magnitude
V = np.cross(normal, U)

# Now, for a point p3 = (x3, y3, z3) it's (u, v) coordinates would be
# computed relative to our reference point (p1)
p3 = np.array([x3, y3, z3])

p3_u = np.dot(U, p3 - p1)
p3_v = np.dot(V, p3 - p1)

# And to convert the point back to 3D, we just use the same reference point
# and multiply U and V by the coordinates
p3_again = p1 + p3_u * U + p3_v * V