svnstrk 133 Report post Posted March 15, 2010 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 0 Share this post Link to post Share on other sites
szecs 2990 Report post Posted March 15, 2010 Maybe this?The first part of my first post 0 Share this post Link to post Share on other sites
svnstrk 133 Report post Posted March 15, 2010 hi, honestly im not quite sure about your post. can you give a more 'human' explanation? :Dbut 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 line4. 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 isv0 (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? 0 Share this post Link to post Share on other sites
szecs 2990 Report post Posted March 15, 2010 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) 0 Share this post Link to post Share on other sites
shmok123 102 Report post Posted March 15, 2010 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. 0 Share this post Link to post Share on other sites
svnstrk 133 Report post Posted March 15, 2010 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. 0 Share this post Link to post Share on other sites
szecs 2990 Report post Posted March 15, 2010 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. 0 Share this post Link to post Share on other sites
svnstrk 133 Report post Posted March 15, 2010 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[u][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 0 Share this post Link to post Share on other sites
szecs 2990 Report post Posted March 15, 2010 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. 0 Share this post Link to post Share on other sites
svnstrk 133 Report post Posted March 15, 2010 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. 0 Share this post Link to post Share on other sites
SuperRad 163 Report post Posted March 15, 2010 Could you maybe be a bit more descriptive (maybe through a diagram) of what you want?Being I think I might understand what you're asking for, but I'm not sure.What I think is you want to rotate the triangle so the plane it occupies becomes parallel with the viewpoint? 0 Share this post Link to post Share on other sites
szecs 2990 Report post Posted March 15, 2010 Sorry, I have no idea what you are talking about.I can image two possible things, both of them were presented, so I guess can't help, sorry.Look at the drawing in the other thread again, and this part:x_a = norm(e1);y_a = norm( cross( cross( e1,e2 ),e1 ) ); 0 Share this post Link to post Share on other sites
svnstrk 133 Report post Posted March 15, 2010 let me elaborate more, im kinda new in this thing so i might miss the term to get it. i have a triangle in 3D space like this:picsnow i want to have an length equally triangle in 2D space like thispicthe question is how can i find the corresponding vertices in 2D, knowing the vertices at 3Dyou can find my intention and solution above. i hope this explain better. sorry for the confusion. any idea is most welcome 0 Share this post Link to post Share on other sites
szecs 2990 Report post Posted March 15, 2010 x_a = norm(e1);y_a = norm( cross( cross( e1,e2 ),e1 ) );these are the two axis of the CS_a.Other parts of the image:Letters without index (by index I mean _letter), are the coordinates in the world CS.x_a1, y_a1 are the coordinates of the vertex number 1, in the triangle's CS_ax_a2, y_a2 are the coordinates of the vertex number 2, in the triangle's CS_ax_a1 = dot(e1,x_a)y_a1 = dot(e1,y_a) = 0x_a2 = dot(e2,x_a)y_a2 = dot(e2,y_a)m_a = [ x_am=dot(n,x_a); y_am=dot(n,y_a) ]m_a can be any arbitrary point.(like in the thread in my first post). Have you taken a look at it at all?Maybe it's not easy to understand, but probably take less time, than waiting for replies. Please, take that time, and try to understand the drawing (especially top-left, and bottom-right). 0 Share this post Link to post Share on other sites