How to transform a set of 3D vectors into a 2D plane, from a view point of another 3D vector?3rd component of a vector from two 2d projectionsCalculating coordinates of a view planeHow are 3d images rendered in 2d space?Apply Euler vector to translate vectorNeed “up” vector to calculate distance from a focal plane given world coordinates (SOLVED)Can you transform any coordinate from any “space” to another “space” that's defined?Transforming coordinate system vs objectsHow can i reflect position and direction vectors from a planeHow to calculate the quaternion from/and axis angle having parent and target position (camera and its target)?How to tumble a camera about a pointrelationship between two planes (or their (N,d) vectors)Rotating cube with cameraTransform vectors from cartesian coordinates to curve coordinate system [2d]
Doesn't allowing a user mode program to access kernel space memory and execute the IN and OUT instructions defeat the purpose of having CPU modes?
Does "Until when" sound natural for native speakers?
Why was Goose renamed from Chewie for the Captain Marvel film?
List elements digit difference sort
How many characters using PHB rules does it take to be able to have access to any PHB spell at the start of an adventuring day?
Vocabulary for giving just numbers, not a full answer
Can you reject a postdoc offer after the PI has paid a large sum for flights/accommodation for your visit?
How to draw cubes in a 3 dimensional plane
Good for you! in Russian
Is "history" a male-biased word ("his+story")?
How to write ı (i without dot) character in pgf-pie
When traveling to Europe from North America, do I need to purchase a different power strip?
What are some noteworthy "mic-drop" moments in math?
When a wind turbine does not produce enough electricity how does the power company compensate for the loss?
Reverse string, can I make it faster?
Could you please stop shuffling the deck and play already?
Find longest word in a string: are any of these algorithms good?
meaning and function of 幸 in "则幸分我一杯羹"
Does the nature of the Apocalypse in The Umbrella Academy change from the first to the last episode?
Why does the negative sign arise in this thermodynamic relation?
How to fix the Unknown Command error caused by starting CmdInit.cmd using TCC/LE?
Is it necessary to separate DC power cables and data cables?
How is the wildcard * interpreted as a command?
Shifting between bemols (flats) and diesis (sharps)in the key signature
How to transform a set of 3D vectors into a 2D plane, from a view point of another 3D vector?
3rd component of a vector from two 2d projectionsCalculating coordinates of a view planeHow are 3d images rendered in 2d space?Apply Euler vector to translate vectorNeed “up” vector to calculate distance from a focal plane given world coordinates (SOLVED)Can you transform any coordinate from any “space” to another “space” that's defined?Transforming coordinate system vs objectsHow can i reflect position and direction vectors from a planeHow to calculate the quaternion from/and axis angle having parent and target position (camera and its target)?How to tumble a camera about a pointrelationship between two planes (or their (N,d) vectors)Rotating cube with cameraTransform vectors from cartesian coordinates to curve coordinate system [2d]
$begingroup$
I googled around a bit, but usually I found overly-technical explanations, or other, more specific Stackoverflow questions on how 3D computer graphics work. I'm sure I can find enough resources for this eventually, but I figured that it's good material for this site...
Lets say that I have a 3D space, with x, y and z coordinates. Then, I have a set of vectors (vertices in computer graphics, I suppose) in that space (they can be forming a cube, for example).
How do I go about transforming them for rendering on a 2D plane (screen)? I need to get x and y coordinates of 2D vectors, but, they need to be dependent on a specific point in space - the camera. When I move the camera, the x and y values should change.
I guess the process will go something like this:
- Translate the 3D vectors according to the camera's x, y and z.
- Rotate the 3D vectors according to the camera's theta and phi (I will need a lot of to polar coordinate system and from polar coordinate system conversions for this, but sin and cos aren't expensive, right?)
- x = x/z, y = y/z, for transforming into 2D, I think, not sure about this part at all, I think I saw it somewhere.
- Scale all vectors according to the camera's distance from the scene (or something else?)
- Render.
I brainstormed these on the fly, there are probably a tonne of better solutions. Also, please try to keep the math simple, as I only know basic trig and calc up to the chain rule, I'm not sure what are people actually using for this. I heard something about "rotation matrices", what are they, exactly? (Well, I'm about to Google that now, but can't hurt me to get an answer here as well.) Also, what are the standard directions for xyz space? (Is z "up"?)
geometry transformation 3d
$endgroup$
|
show 1 more comment
$begingroup$
I googled around a bit, but usually I found overly-technical explanations, or other, more specific Stackoverflow questions on how 3D computer graphics work. I'm sure I can find enough resources for this eventually, but I figured that it's good material for this site...
Lets say that I have a 3D space, with x, y and z coordinates. Then, I have a set of vectors (vertices in computer graphics, I suppose) in that space (they can be forming a cube, for example).
How do I go about transforming them for rendering on a 2D plane (screen)? I need to get x and y coordinates of 2D vectors, but, they need to be dependent on a specific point in space - the camera. When I move the camera, the x and y values should change.
I guess the process will go something like this:
- Translate the 3D vectors according to the camera's x, y and z.
- Rotate the 3D vectors according to the camera's theta and phi (I will need a lot of to polar coordinate system and from polar coordinate system conversions for this, but sin and cos aren't expensive, right?)
- x = x/z, y = y/z, for transforming into 2D, I think, not sure about this part at all, I think I saw it somewhere.
- Scale all vectors according to the camera's distance from the scene (or something else?)
- Render.
I brainstormed these on the fly, there are probably a tonne of better solutions. Also, please try to keep the math simple, as I only know basic trig and calc up to the chain rule, I'm not sure what are people actually using for this. I heard something about "rotation matrices", what are they, exactly? (Well, I'm about to Google that now, but can't hurt me to get an answer here as well.) Also, what are the standard directions for xyz space? (Is z "up"?)
geometry transformation 3d
$endgroup$
1
$begingroup$
If you divide by $z$, then that means that the $z$-axis is pointing away from you (points on the horizon fall close to the center). Mike Abrash's "old" book: Zen of Graphics Programming is useful for learning about how all this was done in DOS-era (in the end he explains how the 3D engine of Doom was coded). Nowadays OpenGL is the rage (Windows gives a standard interface, and graphics card vendors can write there own drivers), and instead of rotation matrices they use quaternions (or so I heard). One aspect you didn't list is 3D-clipping. It is basic analytic geometry, but necessary here.
$endgroup$
– Jyrki Lahtonen
Jul 5 '12 at 17:37
$begingroup$
@JyrkiLahtonen, OK, noted, but clipping is just making stuff that is far off and stuff that is too close disappear, right? I can do that...
$endgroup$
– jcora
Jul 5 '12 at 17:55
1
$begingroup$
I'm sure you can. But you have to clip the stuff outside the so called view frustrum to get it right (the cone from the camera to the viewport extended to infinity). Also: you have to do it before you divide by $z$. Not try to figure it out afterwards as some idiot once tried umpteen years ago (whistles and exits back left).
$endgroup$
– Jyrki Lahtonen
Jul 5 '12 at 18:06
$begingroup$
Wait, but wouldn't the vectors outside of the frustrum just... Be outside? I mean, I haven't done this yet as I've been busy, so I'm not sure...
$endgroup$
– jcora
Jul 5 '12 at 18:41
$begingroup$
If you do polygon based graphics, then clipping helps, when parts of the polygon are outside of the view frustrum and parts are inside. IIRC at a corner it is even possible that parts of the polygon are inside even though all the vertices are outside. Maybe nowadays graphics is not polygon-based? I may be completely out of touch :-)
$endgroup$
– Jyrki Lahtonen
Jul 5 '12 at 18:48
|
show 1 more comment
$begingroup$
I googled around a bit, but usually I found overly-technical explanations, or other, more specific Stackoverflow questions on how 3D computer graphics work. I'm sure I can find enough resources for this eventually, but I figured that it's good material for this site...
Lets say that I have a 3D space, with x, y and z coordinates. Then, I have a set of vectors (vertices in computer graphics, I suppose) in that space (they can be forming a cube, for example).
How do I go about transforming them for rendering on a 2D plane (screen)? I need to get x and y coordinates of 2D vectors, but, they need to be dependent on a specific point in space - the camera. When I move the camera, the x and y values should change.
I guess the process will go something like this:
- Translate the 3D vectors according to the camera's x, y and z.
- Rotate the 3D vectors according to the camera's theta and phi (I will need a lot of to polar coordinate system and from polar coordinate system conversions for this, but sin and cos aren't expensive, right?)
- x = x/z, y = y/z, for transforming into 2D, I think, not sure about this part at all, I think I saw it somewhere.
- Scale all vectors according to the camera's distance from the scene (or something else?)
- Render.
I brainstormed these on the fly, there are probably a tonne of better solutions. Also, please try to keep the math simple, as I only know basic trig and calc up to the chain rule, I'm not sure what are people actually using for this. I heard something about "rotation matrices", what are they, exactly? (Well, I'm about to Google that now, but can't hurt me to get an answer here as well.) Also, what are the standard directions for xyz space? (Is z "up"?)
geometry transformation 3d
$endgroup$
I googled around a bit, but usually I found overly-technical explanations, or other, more specific Stackoverflow questions on how 3D computer graphics work. I'm sure I can find enough resources for this eventually, but I figured that it's good material for this site...
Lets say that I have a 3D space, with x, y and z coordinates. Then, I have a set of vectors (vertices in computer graphics, I suppose) in that space (they can be forming a cube, for example).
How do I go about transforming them for rendering on a 2D plane (screen)? I need to get x and y coordinates of 2D vectors, but, they need to be dependent on a specific point in space - the camera. When I move the camera, the x and y values should change.
I guess the process will go something like this:
- Translate the 3D vectors according to the camera's x, y and z.
- Rotate the 3D vectors according to the camera's theta and phi (I will need a lot of to polar coordinate system and from polar coordinate system conversions for this, but sin and cos aren't expensive, right?)
- x = x/z, y = y/z, for transforming into 2D, I think, not sure about this part at all, I think I saw it somewhere.
- Scale all vectors according to the camera's distance from the scene (or something else?)
- Render.
I brainstormed these on the fly, there are probably a tonne of better solutions. Also, please try to keep the math simple, as I only know basic trig and calc up to the chain rule, I'm not sure what are people actually using for this. I heard something about "rotation matrices", what are they, exactly? (Well, I'm about to Google that now, but can't hurt me to get an answer here as well.) Also, what are the standard directions for xyz space? (Is z "up"?)
geometry transformation 3d
geometry transformation 3d
asked Jun 29 '12 at 21:10
jcorajcora
3402416
3402416
1
$begingroup$
If you divide by $z$, then that means that the $z$-axis is pointing away from you (points on the horizon fall close to the center). Mike Abrash's "old" book: Zen of Graphics Programming is useful for learning about how all this was done in DOS-era (in the end he explains how the 3D engine of Doom was coded). Nowadays OpenGL is the rage (Windows gives a standard interface, and graphics card vendors can write there own drivers), and instead of rotation matrices they use quaternions (or so I heard). One aspect you didn't list is 3D-clipping. It is basic analytic geometry, but necessary here.
$endgroup$
– Jyrki Lahtonen
Jul 5 '12 at 17:37
$begingroup$
@JyrkiLahtonen, OK, noted, but clipping is just making stuff that is far off and stuff that is too close disappear, right? I can do that...
$endgroup$
– jcora
Jul 5 '12 at 17:55
1
$begingroup$
I'm sure you can. But you have to clip the stuff outside the so called view frustrum to get it right (the cone from the camera to the viewport extended to infinity). Also: you have to do it before you divide by $z$. Not try to figure it out afterwards as some idiot once tried umpteen years ago (whistles and exits back left).
$endgroup$
– Jyrki Lahtonen
Jul 5 '12 at 18:06
$begingroup$
Wait, but wouldn't the vectors outside of the frustrum just... Be outside? I mean, I haven't done this yet as I've been busy, so I'm not sure...
$endgroup$
– jcora
Jul 5 '12 at 18:41
$begingroup$
If you do polygon based graphics, then clipping helps, when parts of the polygon are outside of the view frustrum and parts are inside. IIRC at a corner it is even possible that parts of the polygon are inside even though all the vertices are outside. Maybe nowadays graphics is not polygon-based? I may be completely out of touch :-)
$endgroup$
– Jyrki Lahtonen
Jul 5 '12 at 18:48
|
show 1 more comment
1
$begingroup$
If you divide by $z$, then that means that the $z$-axis is pointing away from you (points on the horizon fall close to the center). Mike Abrash's "old" book: Zen of Graphics Programming is useful for learning about how all this was done in DOS-era (in the end he explains how the 3D engine of Doom was coded). Nowadays OpenGL is the rage (Windows gives a standard interface, and graphics card vendors can write there own drivers), and instead of rotation matrices they use quaternions (or so I heard). One aspect you didn't list is 3D-clipping. It is basic analytic geometry, but necessary here.
$endgroup$
– Jyrki Lahtonen
Jul 5 '12 at 17:37
$begingroup$
@JyrkiLahtonen, OK, noted, but clipping is just making stuff that is far off and stuff that is too close disappear, right? I can do that...
$endgroup$
– jcora
Jul 5 '12 at 17:55
1
$begingroup$
I'm sure you can. But you have to clip the stuff outside the so called view frustrum to get it right (the cone from the camera to the viewport extended to infinity). Also: you have to do it before you divide by $z$. Not try to figure it out afterwards as some idiot once tried umpteen years ago (whistles and exits back left).
$endgroup$
– Jyrki Lahtonen
Jul 5 '12 at 18:06
$begingroup$
Wait, but wouldn't the vectors outside of the frustrum just... Be outside? I mean, I haven't done this yet as I've been busy, so I'm not sure...
$endgroup$
– jcora
Jul 5 '12 at 18:41
$begingroup$
If you do polygon based graphics, then clipping helps, when parts of the polygon are outside of the view frustrum and parts are inside. IIRC at a corner it is even possible that parts of the polygon are inside even though all the vertices are outside. Maybe nowadays graphics is not polygon-based? I may be completely out of touch :-)
$endgroup$
– Jyrki Lahtonen
Jul 5 '12 at 18:48
1
1
$begingroup$
If you divide by $z$, then that means that the $z$-axis is pointing away from you (points on the horizon fall close to the center). Mike Abrash's "old" book: Zen of Graphics Programming is useful for learning about how all this was done in DOS-era (in the end he explains how the 3D engine of Doom was coded). Nowadays OpenGL is the rage (Windows gives a standard interface, and graphics card vendors can write there own drivers), and instead of rotation matrices they use quaternions (or so I heard). One aspect you didn't list is 3D-clipping. It is basic analytic geometry, but necessary here.
$endgroup$
– Jyrki Lahtonen
Jul 5 '12 at 17:37
$begingroup$
If you divide by $z$, then that means that the $z$-axis is pointing away from you (points on the horizon fall close to the center). Mike Abrash's "old" book: Zen of Graphics Programming is useful for learning about how all this was done in DOS-era (in the end he explains how the 3D engine of Doom was coded). Nowadays OpenGL is the rage (Windows gives a standard interface, and graphics card vendors can write there own drivers), and instead of rotation matrices they use quaternions (or so I heard). One aspect you didn't list is 3D-clipping. It is basic analytic geometry, but necessary here.
$endgroup$
– Jyrki Lahtonen
Jul 5 '12 at 17:37
$begingroup$
@JyrkiLahtonen, OK, noted, but clipping is just making stuff that is far off and stuff that is too close disappear, right? I can do that...
$endgroup$
– jcora
Jul 5 '12 at 17:55
$begingroup$
@JyrkiLahtonen, OK, noted, but clipping is just making stuff that is far off and stuff that is too close disappear, right? I can do that...
$endgroup$
– jcora
Jul 5 '12 at 17:55
1
1
$begingroup$
I'm sure you can. But you have to clip the stuff outside the so called view frustrum to get it right (the cone from the camera to the viewport extended to infinity). Also: you have to do it before you divide by $z$. Not try to figure it out afterwards as some idiot once tried umpteen years ago (whistles and exits back left).
$endgroup$
– Jyrki Lahtonen
Jul 5 '12 at 18:06
$begingroup$
I'm sure you can. But you have to clip the stuff outside the so called view frustrum to get it right (the cone from the camera to the viewport extended to infinity). Also: you have to do it before you divide by $z$. Not try to figure it out afterwards as some idiot once tried umpteen years ago (whistles and exits back left).
$endgroup$
– Jyrki Lahtonen
Jul 5 '12 at 18:06
$begingroup$
Wait, but wouldn't the vectors outside of the frustrum just... Be outside? I mean, I haven't done this yet as I've been busy, so I'm not sure...
$endgroup$
– jcora
Jul 5 '12 at 18:41
$begingroup$
Wait, but wouldn't the vectors outside of the frustrum just... Be outside? I mean, I haven't done this yet as I've been busy, so I'm not sure...
$endgroup$
– jcora
Jul 5 '12 at 18:41
$begingroup$
If you do polygon based graphics, then clipping helps, when parts of the polygon are outside of the view frustrum and parts are inside. IIRC at a corner it is even possible that parts of the polygon are inside even though all the vertices are outside. Maybe nowadays graphics is not polygon-based? I may be completely out of touch :-)
$endgroup$
– Jyrki Lahtonen
Jul 5 '12 at 18:48
$begingroup$
If you do polygon based graphics, then clipping helps, when parts of the polygon are outside of the view frustrum and parts are inside. IIRC at a corner it is even possible that parts of the polygon are inside even though all the vertices are outside. Maybe nowadays graphics is not polygon-based? I may be completely out of touch :-)
$endgroup$
– Jyrki Lahtonen
Jul 5 '12 at 18:48
|
show 1 more comment
2 Answers
2
active
oldest
votes
$begingroup$
It can be many way to transfer 3d world to 2d plane . I think the basic one is planar projection what I showed in the picture. I made steps for beginners and avoided high mathematics for clear understanding. I believe that rotating is next step after you understand all the points how to transfer one point from 3D into 2D .
I would like to offer which mathematics in this conversion.
As you can see in the figure you want to find m and n values for screen as integer.
1- Define left top point of screen in the plane. $S_1 (x_1, y_1 , z_1)$
2- Define right top point of screen in the plane. $S_2 (x_2, y_2 , z_2)$ . , The width of screen must satisfy $W=sqrt(x_2-x_1)^2+(y_2-y_1)^2+(z_2-z_1)^2$.you can select $z_1=z_2$ for straight view thus $W$ can be $sqrt(x_2-x_1)^2+(y_2-y_1)^2$.
3- Define left bottom point of screen in the plane. $S_3 (x_3, y_3 , z_3)$. The height of screen must satisfy $H=sqrt(x_3-x_1)^2+(y_3-y_1)^2+(z_3-z_1)^2$ and also we know that screen rectangle. it must satisfy $vecS_1S_2 . vecS_1S_3 =0 $ ----> $(x_2-x_1)(x_3-x_1)+(y_2-y_1)(y_3-y_1)+(z_2-z_1)(z_3-z_1)=0 $ Note: If we want straight view, we can select that $x_1=x_3$ and $y_1=y_3$ thus $H$ will be $z_1-z_3$
4- Find the middle point of screen $ M (x_0,y_0,z_0)= (fracx_2+x_32, fracy_2+y_32,fracz_2+z_32)$
5- Define how far camera will be from screen. $(h)$
6-Find camera point: $C(x_c,y_c,z_c)$ you need to find plane equation : $ax+by+cz=1$
three point is enough to define a plane. Thus
-Put Point $S_1$:
$a x_1+by_1+cz_1=1$
-Put Point $S_2$:
$a x_2+by_2+cz_3=1$
-Put Point $M$:
$a x_0+by_0+cz_0=1$
Solve $a,b,c$
and find normalization vector that right angle to the plane
$N= (a_n, b_n ,c_n)= ( fraca sqrta^2+b^2+c^2, fracbsqrta^2+b^2+c^2, fraccsqrta^2+b^2+c^2)$
$C(x_c,y_c,z_c) = (x_0+ha_n,y_0+hb_n,z_0+hc_n)$
7-Find $A'$ that projection of point $A$ on the screen plane.
-Define line between point $C(x_c,y_c,z_c)$ and point $A(x_a,y_a,z_a)$ :
$fracx-x_ax_c-x_a=fracy-y_ay_c-y_a=fracz-z_az_c-z_a=k$
and put $x$,$y$,$z$ into the plane equation ($ax+by+cz=1$) and get an equation depends on $k$ and then solve $k$.You can get $A'(x'_a,y'_a,z'_a)$ from $fracx-x_ax_c-x_a=fracy-y_ay_c-y_a=fracz-z_az_c-z_a=k$ after solving $k$.
8-To find screen angles:
$cos u=fracvecS_1S_2 . vecS_1A'=frac(x_2-x_1)(x'_a-x_1)+(y_2-y_1)(y'_a-y_1)+(z_2-z_1)(z'_a-z_1)Wsqrt(x'_a-x_1)^2+(y'_a-y_1)^2+(z'_a-z_1)^2$ .
$cos v=fracvecS_1S_3 . vecS_1A'=frac(x_3-x_1)(x'_a-x_1)+(y_3-y_1)(y'_a-y_1)+(z_3-z_1)(z'_a-z_1)Hsqrt(x'_a-x_1)^2+(y'_a-y_1)^2+(z'_a-z_1)^2$ .
9-Decision if it is in screen or not: If $cos u >0 $ and $cos v >0 $ then $A'$ is in screen. Otherwise , the point $A'$ is out of screen and we cannot draw $A'$ in 2D screen.
10- Find $m$,$n$, If $cos u >0 $ and $cos v >0 $
$m= sqrt(x'_a-x_1)^2+(y'_a-y_1)^2+(z'_a-z_1)^2 cos u $
$n= sqrt(x'_a-x_1)^2+(y'_a-y_1)^2+(z'_a-z_1)^2 sin u $
We need integers if so we must ignore after point for $m$ and $n$ to get integer values.
Be sure that if $m>W$ and $n>H$ then we cannot draw the point in screen.
Example:
1: $S_1 (400, 400 ,400)$
2: if our screen width:800 pixel $S_2 (880, 1040 , 400)$ $z_1=z_2$ for straight view thus $W=sqrt(880-400)^2+(1040-400)^2=800$
3: $S_3 (400, 400 ,-200)$ thus $H=600$
4: $M (x_0,y_0,z_0)=(640,720,100)$
5: Define how far camera will be from screen. I selected $h=50$ . if h is smaller more area can be seen in screen. It can be changed in software as parameter to get the best view for the screen.
6:Find camera point: $C(x_c,y_c,z_c)$ you need to find plane equation : $ax+by+cz=1$
$400a+400b+400c=1$
$880a+1040b+400c=1$
$640a+720b+100c=1$
here solution that wolfram helped:
$a=frac1100$
$b=-frac3400$
$c=0$
Thus the plane equation of the screen is $frac1100x-frac3400y=1$
$4x-3y=400$
$N= (a_n, b_n ,c_n)= (frac45,-frac35,0)$
$C(x_c,y_c,z_c)=(640+50.frac45,720- 50frac35,100 )=(680,690,100)$
7-Find $A'$ that projection of point $A$ on the screen plane. $A$ given $(0,400,400)$
$fracx680=fracy-400690-400=fracz-400100-400=k$
$4x-3y=400$
$4(680k)-3(290k+400)=400$
$k=frac3237$
$x=680k=680frac3237=frac2176037= approx 588,10$
$y=290k+400=290frac3237+400=frac2408037 approx 650,81$
$z=-300k+400=-300frac3237+400=frac520037 approx 140,54$
8- $ cos u=fracvecS_1S_2 . vecS_1A'=frac480.188,10+640.250,81 800. 406,948approx 0,77038$
$cos v=fracvecS_1S_3 . vecS_1A'=frac(-259,46).(-600) 600. 406,948approx 0,6375$
9- $cos u >0 $ and $cos v >0 $ , thus The point is in screen side.
$ cos uapprox 0,77038$
$sin u approx 0,63758 $
10-
$0,77038.406,948=313,50$ ----->$ m = 314$
$0,63758.406,948=259.46$ ----->$ n= 259$
$m<800$ and $ n<600$ , Thus we can draw the point in the screen.
$m$ and $n$ are selected integer because we needed to find pixel values of the screen.
The example is to demostrate only one point transfer from 3D to 2D. I hope It will give you a start point to use 3d analytic geometry tools for your purpose.
$endgroup$
$begingroup$
very nice explanation at the end
$endgroup$
– user79654
May 27 '13 at 7:43
$begingroup$
@amd Thank you a lot for feedbacks.
$endgroup$
– Mathlover
Jan 16 '17 at 10:35
$begingroup$
Although the geometric meaning of $cos u$ and $cos v$ in steps 8 and 9 is transparent, I think it might be cleaner to obtain $m$ and $n$ from a parametric equation of the image plane. Clipping to the visible portion of the screen becomes a simple range check on $m$ and $n$. That is, set $U=(S_2−S_1)/|S_2−S_1|$ and $V=(S_3−S_1)/|S_3−S_1|$ and solve for $(m,n)$ in $S_1+mU+nV=A′$. The projected point is visible when $0le mle W$ and $0le nle H$.
$endgroup$
– amd
Jan 16 '17 at 19:29
$begingroup$
You could also have found $N$ via a cross product: $(S3-S1)times(S2-S1)$ normalized, or, using the basis vectors from my previous comment, $Vtimes U$, which is guaranteed to be a unit vector by construction. This is, of course, equivalent to solving for a normal from the general equation for the image plane, but much quicker in practice and, I think, just as evident geometrically.
$endgroup$
– amd
Jan 16 '17 at 19:29
add a comment |
$begingroup$
I attended Professor Neil Dodgson's undergraduate lecture series at Cambridge University where he outlined a series of matrix manipulations that in combination, give the result you are asking for. From his 1998 lecture notes:
$endgroup$
$begingroup$
Please note that this is not a trivial topic. There are many surprising results to catch out newcomers; for example, when you project a 3D straight line onto a 2D screen from the perspective of a pinhole camera, the result is usually a 2D curve!
$endgroup$
– Matthew Slyman
Jul 10 '12 at 15:49
1
$begingroup$
The link is broken. (This information comes courtesy of @TemPora, who tried to communicate this through an edit.)
$endgroup$
– Potato
Jun 27 '13 at 7:45
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
return StackExchange.using("mathjaxEditing", function ()
StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix)
StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["$", "$"], ["\\(","\\)"]]);
);
);
, "mathjax-editing");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "69"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
noCode: true, onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmath.stackexchange.com%2fquestions%2f164700%2fhow-to-transform-a-set-of-3d-vectors-into-a-2d-plane-from-a-view-point-of-anoth%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
$begingroup$
It can be many way to transfer 3d world to 2d plane . I think the basic one is planar projection what I showed in the picture. I made steps for beginners and avoided high mathematics for clear understanding. I believe that rotating is next step after you understand all the points how to transfer one point from 3D into 2D .
I would like to offer which mathematics in this conversion.
As you can see in the figure you want to find m and n values for screen as integer.
1- Define left top point of screen in the plane. $S_1 (x_1, y_1 , z_1)$
2- Define right top point of screen in the plane. $S_2 (x_2, y_2 , z_2)$ . , The width of screen must satisfy $W=sqrt(x_2-x_1)^2+(y_2-y_1)^2+(z_2-z_1)^2$.you can select $z_1=z_2$ for straight view thus $W$ can be $sqrt(x_2-x_1)^2+(y_2-y_1)^2$.
3- Define left bottom point of screen in the plane. $S_3 (x_3, y_3 , z_3)$. The height of screen must satisfy $H=sqrt(x_3-x_1)^2+(y_3-y_1)^2+(z_3-z_1)^2$ and also we know that screen rectangle. it must satisfy $vecS_1S_2 . vecS_1S_3 =0 $ ----> $(x_2-x_1)(x_3-x_1)+(y_2-y_1)(y_3-y_1)+(z_2-z_1)(z_3-z_1)=0 $ Note: If we want straight view, we can select that $x_1=x_3$ and $y_1=y_3$ thus $H$ will be $z_1-z_3$
4- Find the middle point of screen $ M (x_0,y_0,z_0)= (fracx_2+x_32, fracy_2+y_32,fracz_2+z_32)$
5- Define how far camera will be from screen. $(h)$
6-Find camera point: $C(x_c,y_c,z_c)$ you need to find plane equation : $ax+by+cz=1$
three point is enough to define a plane. Thus
-Put Point $S_1$:
$a x_1+by_1+cz_1=1$
-Put Point $S_2$:
$a x_2+by_2+cz_3=1$
-Put Point $M$:
$a x_0+by_0+cz_0=1$
Solve $a,b,c$
and find normalization vector that right angle to the plane
$N= (a_n, b_n ,c_n)= ( fraca sqrta^2+b^2+c^2, fracbsqrta^2+b^2+c^2, fraccsqrta^2+b^2+c^2)$
$C(x_c,y_c,z_c) = (x_0+ha_n,y_0+hb_n,z_0+hc_n)$
7-Find $A'$ that projection of point $A$ on the screen plane.
-Define line between point $C(x_c,y_c,z_c)$ and point $A(x_a,y_a,z_a)$ :
$fracx-x_ax_c-x_a=fracy-y_ay_c-y_a=fracz-z_az_c-z_a=k$
and put $x$,$y$,$z$ into the plane equation ($ax+by+cz=1$) and get an equation depends on $k$ and then solve $k$.You can get $A'(x'_a,y'_a,z'_a)$ from $fracx-x_ax_c-x_a=fracy-y_ay_c-y_a=fracz-z_az_c-z_a=k$ after solving $k$.
8-To find screen angles:
$cos u=fracvecS_1S_2 . vecS_1A'=frac(x_2-x_1)(x'_a-x_1)+(y_2-y_1)(y'_a-y_1)+(z_2-z_1)(z'_a-z_1)Wsqrt(x'_a-x_1)^2+(y'_a-y_1)^2+(z'_a-z_1)^2$ .
$cos v=fracvecS_1S_3 . vecS_1A'=frac(x_3-x_1)(x'_a-x_1)+(y_3-y_1)(y'_a-y_1)+(z_3-z_1)(z'_a-z_1)Hsqrt(x'_a-x_1)^2+(y'_a-y_1)^2+(z'_a-z_1)^2$ .
9-Decision if it is in screen or not: If $cos u >0 $ and $cos v >0 $ then $A'$ is in screen. Otherwise , the point $A'$ is out of screen and we cannot draw $A'$ in 2D screen.
10- Find $m$,$n$, If $cos u >0 $ and $cos v >0 $
$m= sqrt(x'_a-x_1)^2+(y'_a-y_1)^2+(z'_a-z_1)^2 cos u $
$n= sqrt(x'_a-x_1)^2+(y'_a-y_1)^2+(z'_a-z_1)^2 sin u $
We need integers if so we must ignore after point for $m$ and $n$ to get integer values.
Be sure that if $m>W$ and $n>H$ then we cannot draw the point in screen.
Example:
1: $S_1 (400, 400 ,400)$
2: if our screen width:800 pixel $S_2 (880, 1040 , 400)$ $z_1=z_2$ for straight view thus $W=sqrt(880-400)^2+(1040-400)^2=800$
3: $S_3 (400, 400 ,-200)$ thus $H=600$
4: $M (x_0,y_0,z_0)=(640,720,100)$
5: Define how far camera will be from screen. I selected $h=50$ . if h is smaller more area can be seen in screen. It can be changed in software as parameter to get the best view for the screen.
6:Find camera point: $C(x_c,y_c,z_c)$ you need to find plane equation : $ax+by+cz=1$
$400a+400b+400c=1$
$880a+1040b+400c=1$
$640a+720b+100c=1$
here solution that wolfram helped:
$a=frac1100$
$b=-frac3400$
$c=0$
Thus the plane equation of the screen is $frac1100x-frac3400y=1$
$4x-3y=400$
$N= (a_n, b_n ,c_n)= (frac45,-frac35,0)$
$C(x_c,y_c,z_c)=(640+50.frac45,720- 50frac35,100 )=(680,690,100)$
7-Find $A'$ that projection of point $A$ on the screen plane. $A$ given $(0,400,400)$
$fracx680=fracy-400690-400=fracz-400100-400=k$
$4x-3y=400$
$4(680k)-3(290k+400)=400$
$k=frac3237$
$x=680k=680frac3237=frac2176037= approx 588,10$
$y=290k+400=290frac3237+400=frac2408037 approx 650,81$
$z=-300k+400=-300frac3237+400=frac520037 approx 140,54$
8- $ cos u=fracvecS_1S_2 . vecS_1A'=frac480.188,10+640.250,81 800. 406,948approx 0,77038$
$cos v=fracvecS_1S_3 . vecS_1A'=frac(-259,46).(-600) 600. 406,948approx 0,6375$
9- $cos u >0 $ and $cos v >0 $ , thus The point is in screen side.
$ cos uapprox 0,77038$
$sin u approx 0,63758 $
10-
$0,77038.406,948=313,50$ ----->$ m = 314$
$0,63758.406,948=259.46$ ----->$ n= 259$
$m<800$ and $ n<600$ , Thus we can draw the point in the screen.
$m$ and $n$ are selected integer because we needed to find pixel values of the screen.
The example is to demostrate only one point transfer from 3D to 2D. I hope It will give you a start point to use 3d analytic geometry tools for your purpose.
$endgroup$
$begingroup$
very nice explanation at the end
$endgroup$
– user79654
May 27 '13 at 7:43
$begingroup$
@amd Thank you a lot for feedbacks.
$endgroup$
– Mathlover
Jan 16 '17 at 10:35
$begingroup$
Although the geometric meaning of $cos u$ and $cos v$ in steps 8 and 9 is transparent, I think it might be cleaner to obtain $m$ and $n$ from a parametric equation of the image plane. Clipping to the visible portion of the screen becomes a simple range check on $m$ and $n$. That is, set $U=(S_2−S_1)/|S_2−S_1|$ and $V=(S_3−S_1)/|S_3−S_1|$ and solve for $(m,n)$ in $S_1+mU+nV=A′$. The projected point is visible when $0le mle W$ and $0le nle H$.
$endgroup$
– amd
Jan 16 '17 at 19:29
$begingroup$
You could also have found $N$ via a cross product: $(S3-S1)times(S2-S1)$ normalized, or, using the basis vectors from my previous comment, $Vtimes U$, which is guaranteed to be a unit vector by construction. This is, of course, equivalent to solving for a normal from the general equation for the image plane, but much quicker in practice and, I think, just as evident geometrically.
$endgroup$
– amd
Jan 16 '17 at 19:29
add a comment |
$begingroup$
It can be many way to transfer 3d world to 2d plane . I think the basic one is planar projection what I showed in the picture. I made steps for beginners and avoided high mathematics for clear understanding. I believe that rotating is next step after you understand all the points how to transfer one point from 3D into 2D .
I would like to offer which mathematics in this conversion.
As you can see in the figure you want to find m and n values for screen as integer.
1- Define left top point of screen in the plane. $S_1 (x_1, y_1 , z_1)$
2- Define right top point of screen in the plane. $S_2 (x_2, y_2 , z_2)$ . , The width of screen must satisfy $W=sqrt(x_2-x_1)^2+(y_2-y_1)^2+(z_2-z_1)^2$.you can select $z_1=z_2$ for straight view thus $W$ can be $sqrt(x_2-x_1)^2+(y_2-y_1)^2$.
3- Define left bottom point of screen in the plane. $S_3 (x_3, y_3 , z_3)$. The height of screen must satisfy $H=sqrt(x_3-x_1)^2+(y_3-y_1)^2+(z_3-z_1)^2$ and also we know that screen rectangle. it must satisfy $vecS_1S_2 . vecS_1S_3 =0 $ ----> $(x_2-x_1)(x_3-x_1)+(y_2-y_1)(y_3-y_1)+(z_2-z_1)(z_3-z_1)=0 $ Note: If we want straight view, we can select that $x_1=x_3$ and $y_1=y_3$ thus $H$ will be $z_1-z_3$
4- Find the middle point of screen $ M (x_0,y_0,z_0)= (fracx_2+x_32, fracy_2+y_32,fracz_2+z_32)$
5- Define how far camera will be from screen. $(h)$
6-Find camera point: $C(x_c,y_c,z_c)$ you need to find plane equation : $ax+by+cz=1$
three point is enough to define a plane. Thus
-Put Point $S_1$:
$a x_1+by_1+cz_1=1$
-Put Point $S_2$:
$a x_2+by_2+cz_3=1$
-Put Point $M$:
$a x_0+by_0+cz_0=1$
Solve $a,b,c$
and find normalization vector that right angle to the plane
$N= (a_n, b_n ,c_n)= ( fraca sqrta^2+b^2+c^2, fracbsqrta^2+b^2+c^2, fraccsqrta^2+b^2+c^2)$
$C(x_c,y_c,z_c) = (x_0+ha_n,y_0+hb_n,z_0+hc_n)$
7-Find $A'$ that projection of point $A$ on the screen plane.
-Define line between point $C(x_c,y_c,z_c)$ and point $A(x_a,y_a,z_a)$ :
$fracx-x_ax_c-x_a=fracy-y_ay_c-y_a=fracz-z_az_c-z_a=k$
and put $x$,$y$,$z$ into the plane equation ($ax+by+cz=1$) and get an equation depends on $k$ and then solve $k$.You can get $A'(x'_a,y'_a,z'_a)$ from $fracx-x_ax_c-x_a=fracy-y_ay_c-y_a=fracz-z_az_c-z_a=k$ after solving $k$.
8-To find screen angles:
$cos u=fracvecS_1S_2 . vecS_1A'=frac(x_2-x_1)(x'_a-x_1)+(y_2-y_1)(y'_a-y_1)+(z_2-z_1)(z'_a-z_1)Wsqrt(x'_a-x_1)^2+(y'_a-y_1)^2+(z'_a-z_1)^2$ .
$cos v=fracvecS_1S_3 . vecS_1A'=frac(x_3-x_1)(x'_a-x_1)+(y_3-y_1)(y'_a-y_1)+(z_3-z_1)(z'_a-z_1)Hsqrt(x'_a-x_1)^2+(y'_a-y_1)^2+(z'_a-z_1)^2$ .
9-Decision if it is in screen or not: If $cos u >0 $ and $cos v >0 $ then $A'$ is in screen. Otherwise , the point $A'$ is out of screen and we cannot draw $A'$ in 2D screen.
10- Find $m$,$n$, If $cos u >0 $ and $cos v >0 $
$m= sqrt(x'_a-x_1)^2+(y'_a-y_1)^2+(z'_a-z_1)^2 cos u $
$n= sqrt(x'_a-x_1)^2+(y'_a-y_1)^2+(z'_a-z_1)^2 sin u $
We need integers if so we must ignore after point for $m$ and $n$ to get integer values.
Be sure that if $m>W$ and $n>H$ then we cannot draw the point in screen.
Example:
1: $S_1 (400, 400 ,400)$
2: if our screen width:800 pixel $S_2 (880, 1040 , 400)$ $z_1=z_2$ for straight view thus $W=sqrt(880-400)^2+(1040-400)^2=800$
3: $S_3 (400, 400 ,-200)$ thus $H=600$
4: $M (x_0,y_0,z_0)=(640,720,100)$
5: Define how far camera will be from screen. I selected $h=50$ . if h is smaller more area can be seen in screen. It can be changed in software as parameter to get the best view for the screen.
6:Find camera point: $C(x_c,y_c,z_c)$ you need to find plane equation : $ax+by+cz=1$
$400a+400b+400c=1$
$880a+1040b+400c=1$
$640a+720b+100c=1$
here solution that wolfram helped:
$a=frac1100$
$b=-frac3400$
$c=0$
Thus the plane equation of the screen is $frac1100x-frac3400y=1$
$4x-3y=400$
$N= (a_n, b_n ,c_n)= (frac45,-frac35,0)$
$C(x_c,y_c,z_c)=(640+50.frac45,720- 50frac35,100 )=(680,690,100)$
7-Find $A'$ that projection of point $A$ on the screen plane. $A$ given $(0,400,400)$
$fracx680=fracy-400690-400=fracz-400100-400=k$
$4x-3y=400$
$4(680k)-3(290k+400)=400$
$k=frac3237$
$x=680k=680frac3237=frac2176037= approx 588,10$
$y=290k+400=290frac3237+400=frac2408037 approx 650,81$
$z=-300k+400=-300frac3237+400=frac520037 approx 140,54$
8- $ cos u=fracvecS_1S_2 . vecS_1A'=frac480.188,10+640.250,81 800. 406,948approx 0,77038$
$cos v=fracvecS_1S_3 . vecS_1A'=frac(-259,46).(-600) 600. 406,948approx 0,6375$
9- $cos u >0 $ and $cos v >0 $ , thus The point is in screen side.
$ cos uapprox 0,77038$
$sin u approx 0,63758 $
10-
$0,77038.406,948=313,50$ ----->$ m = 314$
$0,63758.406,948=259.46$ ----->$ n= 259$
$m<800$ and $ n<600$ , Thus we can draw the point in the screen.
$m$ and $n$ are selected integer because we needed to find pixel values of the screen.
The example is to demostrate only one point transfer from 3D to 2D. I hope It will give you a start point to use 3d analytic geometry tools for your purpose.
$endgroup$
$begingroup$
very nice explanation at the end
$endgroup$
– user79654
May 27 '13 at 7:43
$begingroup$
@amd Thank you a lot for feedbacks.
$endgroup$
– Mathlover
Jan 16 '17 at 10:35
$begingroup$
Although the geometric meaning of $cos u$ and $cos v$ in steps 8 and 9 is transparent, I think it might be cleaner to obtain $m$ and $n$ from a parametric equation of the image plane. Clipping to the visible portion of the screen becomes a simple range check on $m$ and $n$. That is, set $U=(S_2−S_1)/|S_2−S_1|$ and $V=(S_3−S_1)/|S_3−S_1|$ and solve for $(m,n)$ in $S_1+mU+nV=A′$. The projected point is visible when $0le mle W$ and $0le nle H$.
$endgroup$
– amd
Jan 16 '17 at 19:29
$begingroup$
You could also have found $N$ via a cross product: $(S3-S1)times(S2-S1)$ normalized, or, using the basis vectors from my previous comment, $Vtimes U$, which is guaranteed to be a unit vector by construction. This is, of course, equivalent to solving for a normal from the general equation for the image plane, but much quicker in practice and, I think, just as evident geometrically.
$endgroup$
– amd
Jan 16 '17 at 19:29
add a comment |
$begingroup$
It can be many way to transfer 3d world to 2d plane . I think the basic one is planar projection what I showed in the picture. I made steps for beginners and avoided high mathematics for clear understanding. I believe that rotating is next step after you understand all the points how to transfer one point from 3D into 2D .
I would like to offer which mathematics in this conversion.
As you can see in the figure you want to find m and n values for screen as integer.
1- Define left top point of screen in the plane. $S_1 (x_1, y_1 , z_1)$
2- Define right top point of screen in the plane. $S_2 (x_2, y_2 , z_2)$ . , The width of screen must satisfy $W=sqrt(x_2-x_1)^2+(y_2-y_1)^2+(z_2-z_1)^2$.you can select $z_1=z_2$ for straight view thus $W$ can be $sqrt(x_2-x_1)^2+(y_2-y_1)^2$.
3- Define left bottom point of screen in the plane. $S_3 (x_3, y_3 , z_3)$. The height of screen must satisfy $H=sqrt(x_3-x_1)^2+(y_3-y_1)^2+(z_3-z_1)^2$ and also we know that screen rectangle. it must satisfy $vecS_1S_2 . vecS_1S_3 =0 $ ----> $(x_2-x_1)(x_3-x_1)+(y_2-y_1)(y_3-y_1)+(z_2-z_1)(z_3-z_1)=0 $ Note: If we want straight view, we can select that $x_1=x_3$ and $y_1=y_3$ thus $H$ will be $z_1-z_3$
4- Find the middle point of screen $ M (x_0,y_0,z_0)= (fracx_2+x_32, fracy_2+y_32,fracz_2+z_32)$
5- Define how far camera will be from screen. $(h)$
6-Find camera point: $C(x_c,y_c,z_c)$ you need to find plane equation : $ax+by+cz=1$
three point is enough to define a plane. Thus
-Put Point $S_1$:
$a x_1+by_1+cz_1=1$
-Put Point $S_2$:
$a x_2+by_2+cz_3=1$
-Put Point $M$:
$a x_0+by_0+cz_0=1$
Solve $a,b,c$
and find normalization vector that right angle to the plane
$N= (a_n, b_n ,c_n)= ( fraca sqrta^2+b^2+c^2, fracbsqrta^2+b^2+c^2, fraccsqrta^2+b^2+c^2)$
$C(x_c,y_c,z_c) = (x_0+ha_n,y_0+hb_n,z_0+hc_n)$
7-Find $A'$ that projection of point $A$ on the screen plane.
-Define line between point $C(x_c,y_c,z_c)$ and point $A(x_a,y_a,z_a)$ :
$fracx-x_ax_c-x_a=fracy-y_ay_c-y_a=fracz-z_az_c-z_a=k$
and put $x$,$y$,$z$ into the plane equation ($ax+by+cz=1$) and get an equation depends on $k$ and then solve $k$.You can get $A'(x'_a,y'_a,z'_a)$ from $fracx-x_ax_c-x_a=fracy-y_ay_c-y_a=fracz-z_az_c-z_a=k$ after solving $k$.
8-To find screen angles:
$cos u=fracvecS_1S_2 . vecS_1A'=frac(x_2-x_1)(x'_a-x_1)+(y_2-y_1)(y'_a-y_1)+(z_2-z_1)(z'_a-z_1)Wsqrt(x'_a-x_1)^2+(y'_a-y_1)^2+(z'_a-z_1)^2$ .
$cos v=fracvecS_1S_3 . vecS_1A'=frac(x_3-x_1)(x'_a-x_1)+(y_3-y_1)(y'_a-y_1)+(z_3-z_1)(z'_a-z_1)Hsqrt(x'_a-x_1)^2+(y'_a-y_1)^2+(z'_a-z_1)^2$ .
9-Decision if it is in screen or not: If $cos u >0 $ and $cos v >0 $ then $A'$ is in screen. Otherwise , the point $A'$ is out of screen and we cannot draw $A'$ in 2D screen.
10- Find $m$,$n$, If $cos u >0 $ and $cos v >0 $
$m= sqrt(x'_a-x_1)^2+(y'_a-y_1)^2+(z'_a-z_1)^2 cos u $
$n= sqrt(x'_a-x_1)^2+(y'_a-y_1)^2+(z'_a-z_1)^2 sin u $
We need integers if so we must ignore after point for $m$ and $n$ to get integer values.
Be sure that if $m>W$ and $n>H$ then we cannot draw the point in screen.
Example:
1: $S_1 (400, 400 ,400)$
2: if our screen width:800 pixel $S_2 (880, 1040 , 400)$ $z_1=z_2$ for straight view thus $W=sqrt(880-400)^2+(1040-400)^2=800$
3: $S_3 (400, 400 ,-200)$ thus $H=600$
4: $M (x_0,y_0,z_0)=(640,720,100)$
5: Define how far camera will be from screen. I selected $h=50$ . if h is smaller more area can be seen in screen. It can be changed in software as parameter to get the best view for the screen.
6:Find camera point: $C(x_c,y_c,z_c)$ you need to find plane equation : $ax+by+cz=1$
$400a+400b+400c=1$
$880a+1040b+400c=1$
$640a+720b+100c=1$
here solution that wolfram helped:
$a=frac1100$
$b=-frac3400$
$c=0$
Thus the plane equation of the screen is $frac1100x-frac3400y=1$
$4x-3y=400$
$N= (a_n, b_n ,c_n)= (frac45,-frac35,0)$
$C(x_c,y_c,z_c)=(640+50.frac45,720- 50frac35,100 )=(680,690,100)$
7-Find $A'$ that projection of point $A$ on the screen plane. $A$ given $(0,400,400)$
$fracx680=fracy-400690-400=fracz-400100-400=k$
$4x-3y=400$
$4(680k)-3(290k+400)=400$
$k=frac3237$
$x=680k=680frac3237=frac2176037= approx 588,10$
$y=290k+400=290frac3237+400=frac2408037 approx 650,81$
$z=-300k+400=-300frac3237+400=frac520037 approx 140,54$
8- $ cos u=fracvecS_1S_2 . vecS_1A'=frac480.188,10+640.250,81 800. 406,948approx 0,77038$
$cos v=fracvecS_1S_3 . vecS_1A'=frac(-259,46).(-600) 600. 406,948approx 0,6375$
9- $cos u >0 $ and $cos v >0 $ , thus The point is in screen side.
$ cos uapprox 0,77038$
$sin u approx 0,63758 $
10-
$0,77038.406,948=313,50$ ----->$ m = 314$
$0,63758.406,948=259.46$ ----->$ n= 259$
$m<800$ and $ n<600$ , Thus we can draw the point in the screen.
$m$ and $n$ are selected integer because we needed to find pixel values of the screen.
The example is to demostrate only one point transfer from 3D to 2D. I hope It will give you a start point to use 3d analytic geometry tools for your purpose.
$endgroup$
It can be many way to transfer 3d world to 2d plane . I think the basic one is planar projection what I showed in the picture. I made steps for beginners and avoided high mathematics for clear understanding. I believe that rotating is next step after you understand all the points how to transfer one point from 3D into 2D .
I would like to offer which mathematics in this conversion.
As you can see in the figure you want to find m and n values for screen as integer.
1- Define left top point of screen in the plane. $S_1 (x_1, y_1 , z_1)$
2- Define right top point of screen in the plane. $S_2 (x_2, y_2 , z_2)$ . , The width of screen must satisfy $W=sqrt(x_2-x_1)^2+(y_2-y_1)^2+(z_2-z_1)^2$.you can select $z_1=z_2$ for straight view thus $W$ can be $sqrt(x_2-x_1)^2+(y_2-y_1)^2$.
3- Define left bottom point of screen in the plane. $S_3 (x_3, y_3 , z_3)$. The height of screen must satisfy $H=sqrt(x_3-x_1)^2+(y_3-y_1)^2+(z_3-z_1)^2$ and also we know that screen rectangle. it must satisfy $vecS_1S_2 . vecS_1S_3 =0 $ ----> $(x_2-x_1)(x_3-x_1)+(y_2-y_1)(y_3-y_1)+(z_2-z_1)(z_3-z_1)=0 $ Note: If we want straight view, we can select that $x_1=x_3$ and $y_1=y_3$ thus $H$ will be $z_1-z_3$
4- Find the middle point of screen $ M (x_0,y_0,z_0)= (fracx_2+x_32, fracy_2+y_32,fracz_2+z_32)$
5- Define how far camera will be from screen. $(h)$
6-Find camera point: $C(x_c,y_c,z_c)$ you need to find plane equation : $ax+by+cz=1$
three point is enough to define a plane. Thus
-Put Point $S_1$:
$a x_1+by_1+cz_1=1$
-Put Point $S_2$:
$a x_2+by_2+cz_3=1$
-Put Point $M$:
$a x_0+by_0+cz_0=1$
Solve $a,b,c$
and find normalization vector that right angle to the plane
$N= (a_n, b_n ,c_n)= ( fraca sqrta^2+b^2+c^2, fracbsqrta^2+b^2+c^2, fraccsqrta^2+b^2+c^2)$
$C(x_c,y_c,z_c) = (x_0+ha_n,y_0+hb_n,z_0+hc_n)$
7-Find $A'$ that projection of point $A$ on the screen plane.
-Define line between point $C(x_c,y_c,z_c)$ and point $A(x_a,y_a,z_a)$ :
$fracx-x_ax_c-x_a=fracy-y_ay_c-y_a=fracz-z_az_c-z_a=k$
and put $x$,$y$,$z$ into the plane equation ($ax+by+cz=1$) and get an equation depends on $k$ and then solve $k$.You can get $A'(x'_a,y'_a,z'_a)$ from $fracx-x_ax_c-x_a=fracy-y_ay_c-y_a=fracz-z_az_c-z_a=k$ after solving $k$.
8-To find screen angles:
$cos u=fracvecS_1S_2 . vecS_1A'=frac(x_2-x_1)(x'_a-x_1)+(y_2-y_1)(y'_a-y_1)+(z_2-z_1)(z'_a-z_1)Wsqrt(x'_a-x_1)^2+(y'_a-y_1)^2+(z'_a-z_1)^2$ .
$cos v=fracvecS_1S_3 . vecS_1A'=frac(x_3-x_1)(x'_a-x_1)+(y_3-y_1)(y'_a-y_1)+(z_3-z_1)(z'_a-z_1)Hsqrt(x'_a-x_1)^2+(y'_a-y_1)^2+(z'_a-z_1)^2$ .
9-Decision if it is in screen or not: If $cos u >0 $ and $cos v >0 $ then $A'$ is in screen. Otherwise , the point $A'$ is out of screen and we cannot draw $A'$ in 2D screen.
10- Find $m$,$n$, If $cos u >0 $ and $cos v >0 $
$m= sqrt(x'_a-x_1)^2+(y'_a-y_1)^2+(z'_a-z_1)^2 cos u $
$n= sqrt(x'_a-x_1)^2+(y'_a-y_1)^2+(z'_a-z_1)^2 sin u $
We need integers if so we must ignore after point for $m$ and $n$ to get integer values.
Be sure that if $m>W$ and $n>H$ then we cannot draw the point in screen.
Example:
1: $S_1 (400, 400 ,400)$
2: if our screen width:800 pixel $S_2 (880, 1040 , 400)$ $z_1=z_2$ for straight view thus $W=sqrt(880-400)^2+(1040-400)^2=800$
3: $S_3 (400, 400 ,-200)$ thus $H=600$
4: $M (x_0,y_0,z_0)=(640,720,100)$
5: Define how far camera will be from screen. I selected $h=50$ . if h is smaller more area can be seen in screen. It can be changed in software as parameter to get the best view for the screen.
6:Find camera point: $C(x_c,y_c,z_c)$ you need to find plane equation : $ax+by+cz=1$
$400a+400b+400c=1$
$880a+1040b+400c=1$
$640a+720b+100c=1$
here solution that wolfram helped:
$a=frac1100$
$b=-frac3400$
$c=0$
Thus the plane equation of the screen is $frac1100x-frac3400y=1$
$4x-3y=400$
$N= (a_n, b_n ,c_n)= (frac45,-frac35,0)$
$C(x_c,y_c,z_c)=(640+50.frac45,720- 50frac35,100 )=(680,690,100)$
7-Find $A'$ that projection of point $A$ on the screen plane. $A$ given $(0,400,400)$
$fracx680=fracy-400690-400=fracz-400100-400=k$
$4x-3y=400$
$4(680k)-3(290k+400)=400$
$k=frac3237$
$x=680k=680frac3237=frac2176037= approx 588,10$
$y=290k+400=290frac3237+400=frac2408037 approx 650,81$
$z=-300k+400=-300frac3237+400=frac520037 approx 140,54$
8- $ cos u=fracvecS_1S_2 . vecS_1A'=frac480.188,10+640.250,81 800. 406,948approx 0,77038$
$cos v=fracvecS_1S_3 . vecS_1A'=frac(-259,46).(-600) 600. 406,948approx 0,6375$
9- $cos u >0 $ and $cos v >0 $ , thus The point is in screen side.
$ cos uapprox 0,77038$
$sin u approx 0,63758 $
10-
$0,77038.406,948=313,50$ ----->$ m = 314$
$0,63758.406,948=259.46$ ----->$ n= 259$
$m<800$ and $ n<600$ , Thus we can draw the point in the screen.
$m$ and $n$ are selected integer because we needed to find pixel values of the screen.
The example is to demostrate only one point transfer from 3D to 2D. I hope It will give you a start point to use 3d analytic geometry tools for your purpose.
edited 19 hours ago
answered Jul 9 '12 at 10:59
MathloverMathlover
6,25222469
6,25222469
$begingroup$
very nice explanation at the end
$endgroup$
– user79654
May 27 '13 at 7:43
$begingroup$
@amd Thank you a lot for feedbacks.
$endgroup$
– Mathlover
Jan 16 '17 at 10:35
$begingroup$
Although the geometric meaning of $cos u$ and $cos v$ in steps 8 and 9 is transparent, I think it might be cleaner to obtain $m$ and $n$ from a parametric equation of the image plane. Clipping to the visible portion of the screen becomes a simple range check on $m$ and $n$. That is, set $U=(S_2−S_1)/|S_2−S_1|$ and $V=(S_3−S_1)/|S_3−S_1|$ and solve for $(m,n)$ in $S_1+mU+nV=A′$. The projected point is visible when $0le mle W$ and $0le nle H$.
$endgroup$
– amd
Jan 16 '17 at 19:29
$begingroup$
You could also have found $N$ via a cross product: $(S3-S1)times(S2-S1)$ normalized, or, using the basis vectors from my previous comment, $Vtimes U$, which is guaranteed to be a unit vector by construction. This is, of course, equivalent to solving for a normal from the general equation for the image plane, but much quicker in practice and, I think, just as evident geometrically.
$endgroup$
– amd
Jan 16 '17 at 19:29
add a comment |
$begingroup$
very nice explanation at the end
$endgroup$
– user79654
May 27 '13 at 7:43
$begingroup$
@amd Thank you a lot for feedbacks.
$endgroup$
– Mathlover
Jan 16 '17 at 10:35
$begingroup$
Although the geometric meaning of $cos u$ and $cos v$ in steps 8 and 9 is transparent, I think it might be cleaner to obtain $m$ and $n$ from a parametric equation of the image plane. Clipping to the visible portion of the screen becomes a simple range check on $m$ and $n$. That is, set $U=(S_2−S_1)/|S_2−S_1|$ and $V=(S_3−S_1)/|S_3−S_1|$ and solve for $(m,n)$ in $S_1+mU+nV=A′$. The projected point is visible when $0le mle W$ and $0le nle H$.
$endgroup$
– amd
Jan 16 '17 at 19:29
$begingroup$
You could also have found $N$ via a cross product: $(S3-S1)times(S2-S1)$ normalized, or, using the basis vectors from my previous comment, $Vtimes U$, which is guaranteed to be a unit vector by construction. This is, of course, equivalent to solving for a normal from the general equation for the image plane, but much quicker in practice and, I think, just as evident geometrically.
$endgroup$
– amd
Jan 16 '17 at 19:29
$begingroup$
very nice explanation at the end
$endgroup$
– user79654
May 27 '13 at 7:43
$begingroup$
very nice explanation at the end
$endgroup$
– user79654
May 27 '13 at 7:43
$begingroup$
@amd Thank you a lot for feedbacks.
$endgroup$
– Mathlover
Jan 16 '17 at 10:35
$begingroup$
@amd Thank you a lot for feedbacks.
$endgroup$
– Mathlover
Jan 16 '17 at 10:35
$begingroup$
Although the geometric meaning of $cos u$ and $cos v$ in steps 8 and 9 is transparent, I think it might be cleaner to obtain $m$ and $n$ from a parametric equation of the image plane. Clipping to the visible portion of the screen becomes a simple range check on $m$ and $n$. That is, set $U=(S_2−S_1)/|S_2−S_1|$ and $V=(S_3−S_1)/|S_3−S_1|$ and solve for $(m,n)$ in $S_1+mU+nV=A′$. The projected point is visible when $0le mle W$ and $0le nle H$.
$endgroup$
– amd
Jan 16 '17 at 19:29
$begingroup$
Although the geometric meaning of $cos u$ and $cos v$ in steps 8 and 9 is transparent, I think it might be cleaner to obtain $m$ and $n$ from a parametric equation of the image plane. Clipping to the visible portion of the screen becomes a simple range check on $m$ and $n$. That is, set $U=(S_2−S_1)/|S_2−S_1|$ and $V=(S_3−S_1)/|S_3−S_1|$ and solve for $(m,n)$ in $S_1+mU+nV=A′$. The projected point is visible when $0le mle W$ and $0le nle H$.
$endgroup$
– amd
Jan 16 '17 at 19:29
$begingroup$
You could also have found $N$ via a cross product: $(S3-S1)times(S2-S1)$ normalized, or, using the basis vectors from my previous comment, $Vtimes U$, which is guaranteed to be a unit vector by construction. This is, of course, equivalent to solving for a normal from the general equation for the image plane, but much quicker in practice and, I think, just as evident geometrically.
$endgroup$
– amd
Jan 16 '17 at 19:29
$begingroup$
You could also have found $N$ via a cross product: $(S3-S1)times(S2-S1)$ normalized, or, using the basis vectors from my previous comment, $Vtimes U$, which is guaranteed to be a unit vector by construction. This is, of course, equivalent to solving for a normal from the general equation for the image plane, but much quicker in practice and, I think, just as evident geometrically.
$endgroup$
– amd
Jan 16 '17 at 19:29
add a comment |
$begingroup$
I attended Professor Neil Dodgson's undergraduate lecture series at Cambridge University where he outlined a series of matrix manipulations that in combination, give the result you are asking for. From his 1998 lecture notes:
$endgroup$
$begingroup$
Please note that this is not a trivial topic. There are many surprising results to catch out newcomers; for example, when you project a 3D straight line onto a 2D screen from the perspective of a pinhole camera, the result is usually a 2D curve!
$endgroup$
– Matthew Slyman
Jul 10 '12 at 15:49
1
$begingroup$
The link is broken. (This information comes courtesy of @TemPora, who tried to communicate this through an edit.)
$endgroup$
– Potato
Jun 27 '13 at 7:45
add a comment |
$begingroup$
I attended Professor Neil Dodgson's undergraduate lecture series at Cambridge University where he outlined a series of matrix manipulations that in combination, give the result you are asking for. From his 1998 lecture notes:
$endgroup$
$begingroup$
Please note that this is not a trivial topic. There are many surprising results to catch out newcomers; for example, when you project a 3D straight line onto a 2D screen from the perspective of a pinhole camera, the result is usually a 2D curve!
$endgroup$
– Matthew Slyman
Jul 10 '12 at 15:49
1
$begingroup$
The link is broken. (This information comes courtesy of @TemPora, who tried to communicate this through an edit.)
$endgroup$
– Potato
Jun 27 '13 at 7:45
add a comment |
$begingroup$
I attended Professor Neil Dodgson's undergraduate lecture series at Cambridge University where he outlined a series of matrix manipulations that in combination, give the result you are asking for. From his 1998 lecture notes:
$endgroup$
I attended Professor Neil Dodgson's undergraduate lecture series at Cambridge University where he outlined a series of matrix manipulations that in combination, give the result you are asking for. From his 1998 lecture notes:
edited Jun 27 '13 at 12:05
Dan Rust
22.9k114984
22.9k114984
answered Jul 10 '12 at 15:41
Matthew SlymanMatthew Slyman
166
166
$begingroup$
Please note that this is not a trivial topic. There are many surprising results to catch out newcomers; for example, when you project a 3D straight line onto a 2D screen from the perspective of a pinhole camera, the result is usually a 2D curve!
$endgroup$
– Matthew Slyman
Jul 10 '12 at 15:49
1
$begingroup$
The link is broken. (This information comes courtesy of @TemPora, who tried to communicate this through an edit.)
$endgroup$
– Potato
Jun 27 '13 at 7:45
add a comment |
$begingroup$
Please note that this is not a trivial topic. There are many surprising results to catch out newcomers; for example, when you project a 3D straight line onto a 2D screen from the perspective of a pinhole camera, the result is usually a 2D curve!
$endgroup$
– Matthew Slyman
Jul 10 '12 at 15:49
1
$begingroup$
The link is broken. (This information comes courtesy of @TemPora, who tried to communicate this through an edit.)
$endgroup$
– Potato
Jun 27 '13 at 7:45
$begingroup$
Please note that this is not a trivial topic. There are many surprising results to catch out newcomers; for example, when you project a 3D straight line onto a 2D screen from the perspective of a pinhole camera, the result is usually a 2D curve!
$endgroup$
– Matthew Slyman
Jul 10 '12 at 15:49
$begingroup$
Please note that this is not a trivial topic. There are many surprising results to catch out newcomers; for example, when you project a 3D straight line onto a 2D screen from the perspective of a pinhole camera, the result is usually a 2D curve!
$endgroup$
– Matthew Slyman
Jul 10 '12 at 15:49
1
1
$begingroup$
The link is broken. (This information comes courtesy of @TemPora, who tried to communicate this through an edit.)
$endgroup$
– Potato
Jun 27 '13 at 7:45
$begingroup$
The link is broken. (This information comes courtesy of @TemPora, who tried to communicate this through an edit.)
$endgroup$
– Potato
Jun 27 '13 at 7:45
add a comment |
Thanks for contributing an answer to Mathematics Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
Use MathJax to format equations. MathJax reference.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmath.stackexchange.com%2fquestions%2f164700%2fhow-to-transform-a-set-of-3d-vectors-into-a-2d-plane-from-a-view-point-of-anoth%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
$begingroup$
If you divide by $z$, then that means that the $z$-axis is pointing away from you (points on the horizon fall close to the center). Mike Abrash's "old" book: Zen of Graphics Programming is useful for learning about how all this was done in DOS-era (in the end he explains how the 3D engine of Doom was coded). Nowadays OpenGL is the rage (Windows gives a standard interface, and graphics card vendors can write there own drivers), and instead of rotation matrices they use quaternions (or so I heard). One aspect you didn't list is 3D-clipping. It is basic analytic geometry, but necessary here.
$endgroup$
– Jyrki Lahtonen
Jul 5 '12 at 17:37
$begingroup$
@JyrkiLahtonen, OK, noted, but clipping is just making stuff that is far off and stuff that is too close disappear, right? I can do that...
$endgroup$
– jcora
Jul 5 '12 at 17:55
1
$begingroup$
I'm sure you can. But you have to clip the stuff outside the so called view frustrum to get it right (the cone from the camera to the viewport extended to infinity). Also: you have to do it before you divide by $z$. Not try to figure it out afterwards as some idiot once tried umpteen years ago (whistles and exits back left).
$endgroup$
– Jyrki Lahtonen
Jul 5 '12 at 18:06
$begingroup$
Wait, but wouldn't the vectors outside of the frustrum just... Be outside? I mean, I haven't done this yet as I've been busy, so I'm not sure...
$endgroup$
– jcora
Jul 5 '12 at 18:41
$begingroup$
If you do polygon based graphics, then clipping helps, when parts of the polygon are outside of the view frustrum and parts are inside. IIRC at a corner it is even possible that parts of the polygon are inside even though all the vertices are outside. Maybe nowadays graphics is not polygon-based? I may be completely out of touch :-)
$endgroup$
– Jyrki Lahtonen
Jul 5 '12 at 18:48