#### Archived

This topic is now archived and is closed to further replies.

# Point on Sphere intersected by line

This topic is 5360 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi I''m stuck and I need some help. Using C++ and DirectX 9 I simply want to find the most efficient way to calculate a point on a sphere where a line extending from the center intersects the sphere. The line is rotated at angle (rx,ry,rz). Another way to look at this problem is to say I have a line of x length that has one end at a known (x,y,z) and is rotated (rx,ry,rz). I need an easy way to calculate the other end point on the line. Not so good at math so please help. Does directx offer any functions or objects that would make this easy?

##### Share on other sites
Vector Centre(cx, cy, cz)
Vector Dir(rx, ry, rz) // line direction
Vector Point(px, py, pz) // point on sphere
float r // distance of point from centre, or also radius of sphere

Point = Centre + Dir.Normalise() * r;

in other terms

float d_length = (float) sqrt(rx*rx + ry*ry + rz*rz);

px = cx + (rx / d_length) * r;
py = cy + (ry / d_length) * r;
pz = cz + (rz / d_length) * r;

##### Share on other sites
quote:

I simply want to find the most efficient way to calculate a point on a sphere where a line extending from the center intersects the sphere. The line is rotated at angle (rx,ry,rz).

That doesn''t really make a lot of sense... first of all, where is your line rotated from? I would assume you mean rotated from something like (1, 0, 0)?

Secondly, you can rotate your line by angle rx around the x axis, angle ry around the y axis and rz around the z axis... But the order in which you do the rotations will affect the final direction of your line.

Perhaps if you take a step back and tell us what your overall problem is, we can help.

##### Share on other sites
First, figure out what your basis "line" is; i e, what answer do you want when the rotation is 0? Usually, the answer is "X" (1,0,0) but it could be any other vector.

Second, google the Matrix and Quaternion FAQ to find the formula for turning Euler Angles (which is what I think your rotation representation is) into a matrix.

Third, multiply the basis vector by that matrix. The output is the position you seek.

If the input is one of the cardinal axes (X, Y or Z) then you can just extract the first, second or third column from the matrix (assuming translation is the fourth column) because that''s how rotation matrix/bases work.

##### Share on other sites
Assuming (rx,ry,rz) is a point on your line:
just normalise (rx,ry,rz) and multyply it by the radius of the sphere.

##### Share on other sites
I had a problem like this when I was building a combat flight sim. Couldn''t you use quarterions. That''s what I did, and it worked pretty well. The point on the sphere could be a vector.

1. 1
2. 2
Rutin
20
3. 3
khawk
16
4. 4
A4L
14
5. 5

• 12
• 16
• 26
• 10
• 11
• ### Forum Statistics

• Total Topics
633756
• Total Posts
3013709
×