mapping triangle from 3D into 2D

Started by
12 comments, last by szecs 14 years, 1 month ago
hi, im trying to map a triangle from 3D coordinate into 2D coordinate. since its a plane i guess it would fit the 2D coordinate. any1 has any idea or link how to do this? i was thinking to find the lenght of each vector, but than it would not solve where to put the vectpr. any idea? thanks in advance
Advertisement
Maybe this?

The first part of my first post
hi,

honestly im not quite sure about your post. can you give a more 'human' explanation? :D

but i got the rough idea like this:

maybe a little bit explanation about my intention is basically i want to capture a material of a scene. so i have a scene built with triangle. i know the position of each triangle. but not the color whatsoever. and i render the scene once and got the final color of the scene. however, when i want to render it again, im not gonna spend another time to render the scene all over again, instead, im just gonna put my captured image, set it as the triangles material. so im gonna use me method above to generate material for my triangle, which is basically a captured image from the pre-rendered scene.

i have a triangle 3 vertex (x, y, z) and would like to transform it into an 3 vertex (x, y)

1. first i found the distance from v0 (any vertex) and find the length to both other vertex, eg. v1, v2.
2. i calculate the angle between (v1-v0) and (v2-v0)
3. then i put one of the 'line', eg. (v1-v0) as a horizontal line
4. the the second line from v0, i create an line with an angle that i calculated from step 2, and pull it until length on step 1.

so i got my 2d triangle which is compatible with my 3d triangle, and the result vertex is
v0 (0, 0)
v1 (lenght1, 0)
and v2 is something you got from the 4th step above.

my question is: how can you find an x, y equation for a line that has an angle from the horizontal line?

Sorry, I can't give a more "human" explanation. You have to understand the concept of cross-product/dot-product/basis-vectors. I won't try to explain them, because there are plenty of good explanations on the net (for example wiki)
Just throw 1 of the coordinates.
The only problem with this is if your triangle vertical to the plane you map it to. The solution is to throw the coordinate according the normal of the triangle.
hi,

i think the solution given at the link is not what i expected. ofcourse later on i'll deal with that matter. but my current problem is not about finding a point inside the triangle, but more into finding 2D representation of the triangle in 3D.
in the link you gave me, what im trying to find is the p1_c and p2_c, knowing that i put my p0_c in (0, 0). it is possible to do it that way, making the point we're looking is p1_c and p2_c, but im thinking about a better (and faster) way like the steps i;ve stated above.
and my problem is how can you find an x, y equation for a line that has an angle from the horizontal line?

thank you in advance.
So:
You want to "project" a texture to the scene, don't you?
Like you would project an image to an object with a projector, but you are standing precisely where the projector is, so you see the image "un-distorted". Am I right?

If so, then try to look into "space to screen coordinates". I'm not sure how to do that right now, there are plenty of guys who know that from the top of their heads.

let me say this in a better way. im not good at this so sorry for misunderstanding.

what im trying to do:
I have a prerendered scene. objects contain triangles. now i want to capture the render image and keep it as texture for each triangle. so i shoot a ray, find the intersection point and find the corresponding texel at my texture. the concept is easy.

now we go to the detail. to keep my texture image, first i must have an array of RGB value. since texture is 2D image, i have my array with 2 index, let say texture[v]. the first thing i need to do is to find how big my u and v is so the triangle could fit into the array.

let say i put 1 triangle in one array, so i have square to represent a texture of a triangle. now this is what im trying to do for the very first step: finding a proper array to keep my triangle, which means trying to find a suitable triangle in 2D for my 3D triangle.

my idea how to do this:
so basically let say i have a triangle in my scene with vertices v0 (x0, y0, z0), v1 (x1, y1, z1), v2 (x2, y2, z2).
the first thing that come up with my mind is to put v0 on coordinate (0, 0). now the question is, how where to put v1 and v2? my second step (hopefully right) is to find the longest length (v1-v0 or v2-v0) and put it on the horizontal axis, resulting coordinate (length, 0). let say its v1. now my question is, where(how) should i put v2?

after this step, im gonna use the step you presented in your link, which is i think its a barycentric coordinate right?


many thanks in advance
I think I understand the problem.
Please look into "space to screen coordinates" as I suggested (google).
All it does, that it transforms (with a matrix) your coordinates to screen coordinates, (so you will know where a vertex will be on the screen), after that, all you have to to is mapping the values to 0...1 range, and you have your texture coordinates. You assign these texture cooedinates to the corresponding vertex, then apply the image as texture. You are over-complicating the problem.

I hope that's clear.
yes i did look for that topic but it gives me (perspective) projection from 3D space to the screen, which is not what i want. what i need (or at least i think what i need) is a way to have a 2D representation of my 3D triangle with the same length.

imagine if you have a triangle in real life, and then you want to, let say, draw on it. you put it on a table hence it become a flat triangle with x, y coordinate. thats what i want to have. any help would be great.

This topic is closed to new replies.

Advertisement