Recent

Author Topic: How to transfer 3D coordinates into 2D coordinates  (Read 13293 times)

Rado

  • Guest
How to transfer 3D coordinates into 2D coordinates
« on: June 14, 2006, 03:24:22 pm »
Hello and thanks in regards for all your answers. I want to visualiza 3D points on a canvas of an image, for example first point with coordinates x 10, y 20, z 30, second point x 40 y 10 z 50 and so on. I know how to put pixels on a canvas with lazarus, but the pixels are in 2D coordinates. How to transfer the 3D coordinates into 2D coordinates?

christophe_D

  • New Member
  • *
  • Posts: 20
How to transfer 3D coordinates into 2D coordinates
« Reply #1 on: June 14, 2006, 05:59:53 pm »
there is 2 solutions

the easy one

we used the y abisses at 45 ° the most simple

for point in (1,0,0) we must paint a point with coordinates (1,0)
for point in (0,0,1) we must paint a point with coordinates (0,1)
for point in (0,1,0)  paint a point with coordinates (0.5,0.5)

finally the solution is paint (x+y*0.5,z+y*0.5)

the other little difficult

i used the old system for draw a circle
like this
pi:=3.1415926
for i:=0 to 360 do
begin
  x:=cos(i*pi/180)*rayon+centerX;
  y:=sin(i*pi/180)*rayon+centerY;
  // and paint a point at with coordinates (x,y)
end;

so if you want to have the y abisse at 30°for example

AngX:=cos(30*pi/180)
Angy:=sin(30*pi/180)
and paint a point at coordinates (x+y*AngX,z+y*AngY)

and to finish with this 2 solutions dont forget if you want the 0,0 point in the center of the screen
for example if you have a screen with width 800*600
the drawline line become (x+y*AngX+400,z+y*AngY+300)

that all ...

hum ... is it that can help you ???

Anonymous

  • Guest
How to transfer 3D coordinates into 2D coordinates
« Reply #2 on: June 15, 2006, 10:14:12 pm »
Thanks for the answer :) I looked in several forums and found another formula. First is calculated the following:
 Xt := (Mx + X*Cos(A) - Y*Sin(A));
 Yt := (My + X*Sin(A)*Sin(B) + Y*Cos(A)*Sin(B) + Z*Cos(B));
Mx and My are the positions of the coordinate, aand A and B are some angles that i didn't understand what exactly angles are they, X Y and Z are the coordinates of the 3D dot.
After that are being calculated the final X and Y coordinater:
 X_final := CentreX + Round(Xt);
 Y_final := CentreY - Round(Yt);
I am not actually sure what are CenterX and CentreY. However thay must be somewhat connected with the Mx and My values.

christophe_D

  • New Member
  • *
  • Posts: 20
How to transfer 3D coordinates into 2D coordinates
« Reply #3 on: June 16, 2006, 01:30:17 pm »
Quote from: "Anonymous"
Thanks for the answer :) I looked in several forums and found another formula. First is calculated the following:
 Xt := (Mx + X*Cos(A) - Y*Sin(A));
 Yt := (My + X*Sin(A)*Sin(B) + Y*Cos(A)*Sin(B) + Z*Cos(B));
Mx and My are the positions of the coordinate, aand A and B are some angles that i didn't understand what exactly angles are they, X Y and Z are the coordinates of the 3D dot.
After that are being calculated the final X and Y coordinater:
 X_final := CentreX + Round(Xt);
 Y_final := CentreY - Round(Yt);
I am not actually sure what are CenterX and CentreY. However thay must be somewhat connected with the Mx and My values.


it's look like my answer but with this you can have a angle for Z absisse , and X too...

dmantione

  • Newbie
  • Posts: 2
How to transfer 3D coordinates into 2D coordinates
« Reply #4 on: June 28, 2006, 10:10:01 pm »
This is for a parallel projection. For a perspective projection things are much simpler:
Code: [Select]

   

        |     ..O
        |  ...  |
       ....     |
   .... |       |
...     |       |
E-------|-------- - - - Z
        |
        |       |

        D       |
                X



Suppose you have a point O with coordinates (x,y,z) which needs to be projected to (dx,dy). The above drawing shows how to calculate dx. E is the eye, D the display you want to project on. X the X-axis, Z the z-axis.

You know the distance between the eye and the display, lets call it v. You also know the distance on the z axis, which is the Z coordinate.

x/dx=z/v

Using this formula you can calculate dx.

Calculation of dy can be done with exactly the same method and you end up with:

y/dy=z/v

Danail

  • Full Member
  • ***
  • Posts: 151
How to transfer 3D coordinates into 2D coordinates
« Reply #5 on: October 09, 2006, 03:22:55 pm »
So in the upper formulas what is which?

Xt := (Mx + X*Cos(A) - Y*Sin(A));
Yt := (My + X*Sin(A)*Sin(B) + Y*Cos(A)*Sin(B) + Z*Cos(B));
What are Mx My and the two angles A and B

And in the final calculation what is CentrX and CentreY?
X_final := CentreX + Round(Xt);
Y_final := CentreY - Round(Yt);

Bad Sector

  • Jr. Member
  • **
  • Posts: 69
    • Runtime Terror
How to transfer 3D coordinates into 2D coordinates
« Reply #6 on: November 08, 2006, 03:20:05 pm »
3D programmer here!

All the above may work, but they're too complicated and not clear :-). So, here is what i use when doing software 3d->2d projections (usually for software 3d rendering :-):

Code: [Select]

x_2d = x_3d * 256 / z_3d + screen_horizontal_center
y_2d = y_3d * 256 / z_3d + screen_vertical_center


(note: that 256 can be replaced with a shiftleft operation of 8 bits - but i think that the compiler does that automatically where possible :-).

In the above formulas, x_2d and y_2d are screen coordinates (that is, Canvas pixels) and x_3d, y_3d and z_3d are 3D world coordinates. screen_horizonal_center and screen_vertical_center are what the name specifices, but instead of screen think Canvas :-). Just use Canvas.Width div 2 and Canvas.Height div 2.
Kostas "Bad Sector" Michalopoulos
Runtime Terror

 

TinyPortal © 2005-2018