Skip to main content
gamedev.net
🔒 Locked

3d line segment

Started by phaelax 6 replies 550+ views
Original Post
phaelax
phaelax
If I know 1 point(point A) and two angle''s of rotation(x and y), and the distance from from point A in 3D space, how could I find the coordinates for point B?
Atheist
Atheist
Depends on what your angles x and y refer to. But in general try constructing a direction u (unit vector) from your angles. Then:
b = a + d*u
where d is the distance while a and b are the coordinates of point A and B respectively.
oliii
oliii
that would be something like that

Dir.x = cos(rotation) * cos(elevation);
Dir.y = sin(elevation);
Dir.z = sin(rotation) * cos(elevation);

B.x = A.x + Dir.x * distance;
B.y = A.y + Dir.y * distance;
B.z = A.z + Dir.z * distance;
Everything is better with Metal.
phaelax
phaelax
thx guys. I came up with this just before I checked back here.

height = sin(elevation) * distance
gdistance = cos(elavation) * distance

b.x = a.x + cos(Yrotation) * gdistance
b.y = a.y + height
b.z = a.z + sin(Yrotation) * gdistance
oliii
oliii
To be fair, it''s not that advanced. For example, if you pickup the OpenGL red book, it''s in there. I did a Master in Computer Graphics & Virtual Reality, and yeah, I learned a few tricks there, but it''s trigonometry, coordinate systems (it''s like latitude / longitude earth coordinates). You can pretty much self teach these things with books, the net, and coding, once you know basic vector maths, trig, algebra, good A-level maths, really. All the rest come with experience. And I do work in the game industry, so it''s my job to know

A lot of people around here know that stuff, I''m just a bit quicker at replying. But thanks anyway.
Everything is better with Metal.
phaelax
phaelax
There''s a book with those equations in it? I just looked at it in terms of 2 dimensions at first, cause that''s easier. I came up with that by using pythagorean theorem.
oliii
oliii
that''s a very good effort indeed

It''s a lot easier to visualise if you draw it on paper, then you can see the angles and their relationship, the way they describe a sphere. It''s a polar coordinate system, where coordinates are not expressed as (x, y, z), but with (theta, phi, rho), where ''theta'' is your ''rotation'' angle (longitude), ''phi'' is your ''elevation'' angle (or latitude), and ''rho'' is the distance from origin (can be compared with an ''altitude'', a distance from earth''s centre). (all greek lettersare just for conventions ).

Then the operation I describe and that you came up with, is a conversion from polar coordinates to cartesian orthogonal coordinates ((x, y, z) triple to you and me).

then you have the inverse operation. From cartesian to polar. Have fun working that one out
Everything is better with Metal.

Topic Locked

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

Sign in to reply to this topic.