how to find x,y,z of a point in a sphere if I'm in the center of a sphere?

Started by
10 comments, last by JoeJ 8 years, 1 month ago

True story. Thanks very very very much for the explanation, really. I'm mad at myself now, because I messed up the topic's name and I can't rename it properly, so other people can come here and see how this works, because I searched everywhere, but there weren't any explanations that were nearly as good as this one. TY MAN :cool:

Advertisement


EDIT: I think i can write a much better explantation, but no time at the moment...

... i'll add the 'better' explantation anyways, because it requires no matrix knowledge.

It's about using two perpendicular unit vectors and sin/cos again, i'll refer to the vectors as basis vectors, e.g.:

vec3 basis0 (1,0,0);
vec3 basis1 (0,0,1);

We can draw a circle to visualize how to calculate a angled direction from them:

for (float angleH = 0; angleH < PI*2; angleH+=PI/100)
{
vec3 dir =
basis0 * sin(angleH)
+
basis1 * cos(angleH);
 
RenderPoint (dir); // dir always unit length -> nice circle
}

Understanding this is all you need, because the second angle we handle next uses the same math:

basis0 =
vec3 (1,0,0) * sin(angleV)
+
vec3 (0,1,0) * cos(angleV);

basis0 has been rotated in the xy plane, but it is still unit length and perpendicular to basis1.

You can repeat the circle rendering code here and it will show a rotated circle.

Then you can optimize the code and you will get the same kind of math as in your first code snippet.

This should help to understand it well.

This topic is closed to new replies.

Advertisement