Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert a 3D point on a plane to UV coordinates?

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.

like image 242
tigrou Avatar asked Sep 06 '13 17:09

tigrou


People also ask

How do UV coordinates work?

The UV mapping process involves assigning pixels in the image to surface mappings on the polygon, usually done by "programmatically" copying a triangular piece of the image map and pasting it onto a triangle on the object.

Where are UV coordinates stored?

Texture coordinates, also called UVs, are pairs of numbers stored in the vertices of a mesh. These numbers are often used to stretch a 2D texture onto a 3D mesh, but they can be used for other things like coloring the mesh (see Vertex color), controlling the flow across the surface (see Flow map), etc.

What does the UV in UV mapping correspond with?

UVs are two-dimensional texture coordinates that correspond with the vertex information for your geometry. UVs are vital because they provide the link between a surface mesh and how an image texture gets applied onto that surface.


1 Answers

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.      

like image 158
sbabbi Avatar answered Sep 22 '22 23:09

sbabbi