How to transfer 3D coordinates into 2D coordinates lazarus / 9-Editor ---------------------------------------------------------------------- Rado · 2006-06-14 13:24 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 · 2006-06-14 15:59 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 · 2006-06-15 20:14 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 · 2006-06-16 11:30 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 · 2006-06-28 20:10 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 · 2006-10-09 13:22 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 · 2006-11-08 14:20 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.