Re: 3-d equation
- Posted by "Graeme." <hmi at POWERUP.COM.AU> Aug 29, 1998
- 524 views
At 17:13 26/08/98 -0400, you wrote: >Could someone please give me an equation or an algorithm to >display a >set of 3-d points on a x-y coordinate system? function transform(sequence point,sequence angles, integer d) atom a,b,c sequence sine,cosine sine=sin(angles) cosine=cos(angles) a=point[1]*cosine[1]+point[2]*sine[1] b=point[2]*cosine[1]-point[1]*sine[1] c=point[3]*cosine[2]-a*sine[2] a=d-(a*cosine[2]+point[3]*sine[2]) return floor({((b*cosine[3]+c*sine[3])*d)/a, ((c*cosine[3]-b*sine[3])*d)/a}) end function This function will return a set of 2D co-ords from a 3D point and 3 rotation angles. the parameters are : point : {x,y,z} angles : {alpha, beta, gamma} in radians d : Distance between view point and projection plane The output will have to be scaled to fit your screen. i.e. constant scale={3,2} -- insert appropriate values here sequence p2d,p3d,ang p3d={28,9,18} ang={1.3,0.4,5.6} p2d=transform(p3d,ang,80)*scale The d parameter affects the severity of the perspective applied to the transformation, play around with it until you find a value you like. If you are transforming a lot of points at the same rotation angles (highly likely), you will want to remove the cos() and sin() calls from inside the function to avoid them being re-calculated for each point. Hope this helps. Graeme. ----------------------------------------------------