Skip to main content
GameDev.net gamedev.net
🔒 Locked

Distance formula 3d

Started by treknerd Jan 5, 2002 at 4:36 PM 6 replies 28.2k views
Original Post
treknerd
treknerd
Just curious--is there a formula to find the distance between two points in 3d space? (say x1,y1,z1 and x2,y2,z2)
untalkative_monkey
untalkative_monkey
yeah

dist = sqrt((x2-x1)^2 + (y2-y1)^2 + (z2-z1)^2)



...go on and live with no regrets, you only have one life...
...go on and live with no regrets, you only have one life...
EDI
EDI
Simple=)
deltax=x2-x1;
deltay=y2-y1;
deltaz=z2-z1;
distance=sqrt((deltax*deltax)+(deltay*deltay)+(deltaz*deltaz))


;-)

Raymond Jacobs,
Developer,
www.EtherealDarkness.com
treknerd
treknerd
Thanks. I thought it might be something like that, but I wasn''t sure.

-treknerd
untalkative_monkey
untalkative_monkey
glad to help.... FIRST!

...go on and live with no regrets, you only have one life...
...go on and live with no regrets, you only have one life...
treknerd
treknerd
yeah, you replied 4 minutes after my post. That''s really quick!
Okidata26
Okidata26
On the tail end of this animal
I have a question on how distance in world space relates to screen space


Let see if I can get my point across correctly
You have a line segment represented by 3d endpoints A and B
its the distance between these points we''ll denote as Lw
(Length in World Space) but I need to know what the segments Ls
(Length in Screen Space) is basically its length in pixels

if the Z axis is perpendicular to the view plane (monitor) then as Segment AB''s Z increases or decreses the distance between A&B will always be Lw but Ls is going to change.

In otherwords it takes more pixels to represent a line as it gets closer to the eye and less further away

Things I already know
screen resolution and aspect ratio are going to have an impact on this relationship.

10Q in Advanced


No Matter what it is (programming related)...Some Assembly Required.
In any good program remember there's ...Some Assembly Required.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.