Computer Science Canada

More help with Math needed

Author:  Danjen [ Thu Jan 11, 2007 8:32 pm ]
Post subject:  More help with Math needed

Okay, here's what I need help with:
I am making a 3D rendering program from scratch (I'm crazy like that Smile ), and I need to determine the distance between two points with three axes (x,y,z). I need to come up with a formula, and so far I've worked it out to cuberoot ((((x1+x2+x3)/3)**2 + ((y1+y2+y3)/3)**2 + ((z1+z2+z3)/3)**2)/3). I'm not sure if that's what it should be, but the outcome seems reasonable. Also, how would one determine the cubic root of a number in turing? As you can see, I used it in that formula but I'm not sure how to actually get the cube root Sad . Finally, for the 3D engine itself; I heard I have to use (x / z) and (y / z) for something... what specifically? Lastly, what is the advantage of using exported qualified commands over non-exported qualified commands (like Draw.Line and drawline)? Thanks in advance Smile

Author:  rdrake [ Thu Jan 11, 2007 8:49 pm ]
Post subject:  RE:More help with Math needed

As I recall one would have to use the formula D = sqrt((x1 - x2)^2 + (y1 + y2)^2 + (z1-z2)^2) in order to achieve this.

Author:  Danjen [ Thu Jan 11, 2007 9:05 pm ]
Post subject:  Re: More help with Math needed

Oh ... heh I didn't think it would be that simple actually. Surprised

Author:  Clayton [ Thu Jan 11, 2007 11:13 pm ]
Post subject:  Re: More help with Math needed

you use the (x/z) (y/z) for depth (ie, to add the 3D element).

The advantage to using Procedures and Functions from modules (Export qualified proc/fcn's) is that it introduces you to the idea of modularity, meaning if I asked you where the method Line was, you could tell me exactly where it is; in the Draw Module. With something like drawline() however, you have no idea where the code for it is stored, the best you can do is guess.

Author:  zylum [ Thu Jan 11, 2007 11:36 pm ]
Post subject:  Re: More help with Math needed

rdrake > your plus in the y portion should be a minus so,

D = sqrt[(x2-x1)^2 + (y2-y1)^2 + (z2-z1)^2]


The division by the z component is for adding perspective which gives the illusion of depth.

You could do cube root in turing by doing ' **(1/3) ' -> ie exponentiate to 1/3.

Author:  rdrake [ Thu Jan 11, 2007 11:49 pm ]
Post subject:  Re: More help with Math needed

zylum @ Thu Jan 11, 2007 11:36 pm wrote:
rdrake > your plus in the y portion should be a minus so,
Whoopsies, yes, it should be. Editing... wait, I can't... :S.

Author:  Danjen [ Fri Jan 12, 2007 10:02 am ]
Post subject:  Re: More help with Math needed

Ok, so would I use (x/z) and (y/z) in the drawing of the object, like object.X + (x/z) etc?

Author:  rdrake [ Fri Jan 12, 2007 10:47 am ]
Post subject:  Re: More help with Math needed

Danjen @ Fri Jan 12, 2007 10:02 am wrote:
Ok, so would I use (x/z) and (y/z) in the drawing of the object, like object.X + (x/z) etc?
I recommend you read up on perspective. GameDev.net has many excellent articles, including those on matrices.

Reading up on matrices in general would also be a good idea Smile.


: