View Full Version : 3d Maths

roger ramjet

07-29-2002, 10:48 PM

Hi im pretty stupid when it comes to maths but i really need help with a couple of formulas.

I need something that will allow me to get all of the points in a straight line in 3d .. i know 2d is y=mx+b but i have no idea what it is in 3d

Also i need help in the point formula for circles in 2d and 3d .. i havnt done anymaths for a few years and i forgot all the stuff i learnt at school . If anybody can explain this in lamen terms or point me to a web page that would be great .

Thanx heaps

thelamberto

07-30-2002, 01:48 AM

Hi,

In 3D you can specify a line using a point on the line and a vector co-directed (ie parallel) thus giving any arbitrary point on the line.

Say P is point on the line ie Px, Py, Pz.

X is an arbitrary point on the line x, y, z.

V is the co-directed vector Vx, Vy, Vz then in parametric form:

X = P + tC where t represents all real numbers.

Thus by varying t you move along the line.

If you know 2 points on the line instead of a point and a vector then, V = (P1 - P2), and the above equation can be used.

Written in standard form the equation joining two points P1(x1 y1,z1) and P2(x2,y2,z2) is:

(x-x1)/(x2-x1) = (y-y1)/(y2-y1) = (z-z1)/(z2-z1)

Rewriting with (x2-x1)=l, (y2-y1)=m, (z2-z1)=n

(x-x1)/l = (y-y1)/m = (z-z1)/n

The equation of a shere is:

(x-x0)^2 + (y-y0)^2 + (z-z0)^2 = R^2

where the sphere's origin is at (x0,y0,z0) and radius R.

In 2D just remove the z bits.

[This message has been edited by thelamberto (edited 07-30-2002).]

fringe

07-30-2002, 01:57 AM

Hey,

I am pretty good at the maths but only a beginner at OpenGL so I don't know if this is a good form in which to look at this but here goes.

For 2D circles the easiest method is to define a angle (theta) Then all the points on a circle are:

x=radius * cos(theta) + x centre of circle

y=radius * sin(theta) + y centre of circle

Then if you take theta from 0 - 2pi (360 degrees) you have all the points. If you want it in the form of y=mx+c it more tricky

y= square root of((x- x centre of cicrle)^2 - radius^2 ) - y centre of circle

where ^2 means squared

for a line I prefer to think in vectors. Imagine drawing a line by starting at a point on the line then drawing in one direction. This is easily done in vectors:

points on line = a + lambda * b

where a is a point on the line, b is a vector in the direction of the line and lambda is changed in value to reflect all the points on the line. from - infinity to + infinity. So for example a line through (1,1,0) in the x direction is given by:

point = (1,1,0) + lambda * (1,0,0)

or x point = 1 + lambda * 1

y point = 1 + lambda *0

z point = 0 + lambda *0

then increase lambda from -10 to 10 gets you a line 20 units long.

hope this is clear not really suire I have made sense.

For cicles in 3D I don't know have to think but you could just rotate and translate then draw 2D circle?

Hope it helps,

Fringe

roger ramjet

07-30-2002, 04:37 PM

thanx heaps for your help guys im only a newbie and for 2 people to describe how to do it so quickly is great .. who knows maybe i will be coding the quake 5 engine one day ... ha ha thanks peoples

Powered by vBulletin® Version 4.2.5 Copyright © 2018 vBulletin Solutions Inc. All rights reserved.