# Point to Sphere calculation

• Oct 21st 2010, 03:36 PM
EEalgorithm
Point to Sphere calculation
Ok I am not exactly sure what subject this goes under as I can't find a good way of calculating it in my calc book and racked my brain for other methods, but I am stumped. Ok basically here is the problem.
I know my position in space, any coordinate system will do. I am inside of a sphere that has radius r. Knowing my position and a vector pointing at a known angle, I need to figure out where the vector and the sphere intersect.

That seems a little convoluted, so I will try to explain the practical application.
I know my position on earth (latitude, longitude, altitude).
I know exactly where the sun is with respect to me (Zenith angle, Azimuth angle)
If I look directly at the sun (DO NOT ATTEMPT), where does the vector I am looking at intersect with a sphere that has a radius of 1000 meters greater than my current altitude.
Keep in mind that the earth curves, so a simple trig calculation doesn't do the trick.

It seems so simple, but I just can not figure out how to solve it.
If anyone could point me toward a theorem or technique or law I would appreciate it.
• Oct 22nd 2010, 09:01 AM
Ackbeet
Let the center of the sphere of radius $\displaystyle r$ be the origin $\displaystyle O.$ Let the current position of the observer be at a known vector $\displaystyle \mathbf{P}$ with respect to the origin. Let the known vector pointing to some object (such as the sun) from the observer be denoted $\displaystyle \mathbf{Q}.$ Let the smaller angle between $\displaystyle \mathbf{P}$ and $\displaystyle \mathbf{Q}$ be denoted $\displaystyle \varphi.$ This angle is known. Let the vector from the origin to the intersection of the sphere and $\displaystyle \mathbf{Q}$ be denoted $\displaystyle \mathbf{R}.$ Finally, let the vector $\displaystyle \mathbf{q}:=\mathbf{R}-\mathbf{P}.$

We know that $\displaystyle |\mathbf{R}|=r.$ We also know that $\displaystyle \mathbf{P}+\mathbf{q}=\mathbf{R}.$ Hence,

$\displaystyle |\mathbf{R}|^{2}=\mathbf{R}\cdot\mathbf{R}=(\mathb f{P}+\mathbf{q})\cdot(\mathbf{P}+\mathbf{q})=P^{2} +q^{2}-2Pq\cos(\varphi)=r^{2}.$

Rearranging, we obtain

$\displaystyle q^{2}-2qP\cos(\varphi)+P^{2}-r^{2}=0.$

Viewing this is a quadratic in $\displaystyle q$, we find the two solutions

$\displaystyle q=P\cos(\varphi)\pm\sqrt{r^{2}-P^{2}+P^{2}\cos^{2}(\varphi)}.$

Because $\displaystyle r>P,$ we may throw out the negative square root solution, since $\displaystyle q>0.$ Hence,

$\displaystyle q=P\cos(\varphi)+\sqrt{r^{2}-P^{2}\sin^{2}(\varphi)}.$

Now, the direction of $\displaystyle \mathbf{Q}$ is the same as the direction of $\displaystyle \mathbf{q}.$ Hence, we can write

$\displaystyle \mathbf{q}=q\,\dfrac{\mathbf{Q}}{Q}=\left(P\cos(\v arphi)+\sqrt{r^{2}-P^{2}\sin^{2}(\varphi)}\right)\dfrac{\mathbf{Q}}{Q }.$

Finally, we write

$\displaystyle \mathbf{R}=\mathbf{P}+\left(P\cos(\varphi)+\sqrt{r ^{2}-P^{2}\sin^{2}(\varphi)}\right)\dfrac{\mathbf{Q}}{Q }.$

This is the desired vector in terms of known quantities, and is thus a solution to your problem.

Make sense?
• Oct 22nd 2010, 11:55 AM
EEalgorithm
Well it makes sense, and thanks for the reply, but I was aware of this solution and there is one problem. I do not know the angle gamma.
I believe in this setup q is the vector between point p and the intersection of q and the sphere. If my understanding is correct.
So in the terms that you have set up. I am aware of.
vector p
The angle between vector p and and the vector pointing at the intersection on the sphere.
That is where my problem comes in.
I have attached a crude drawing of my problem. please note that the I merely extended the line from point P for clarity showing that it is in fact the angle between point P and the sun. The actual vector ends at the intersection of the sphere.
Attachment 19418
• Oct 22nd 2010, 12:10 PM
Ackbeet
The angle phi, written $\displaystyle \varphi$ and pronounced /FEE/, is the angle between vector $\displaystyle \mathbf{P}$ and $\displaystyle \mathbf{Q}.$ That is precisely the angle that I'm using here, and that, in your drawing, you mark as "known". Are you saying that you don't know the direction of $\displaystyle \mathbf{Q}?$ If so, I'd say your problem is unsolvable.

Here is my drawing of the problem. The capital letters are all vectors, and $\displaystyle \phi=\varphi.$

Attachment 19419

What exactly in this formula don't you know:

$\displaystyle \displaystyle\mathbf{R}=\mathbf{P}+\left(P\cos(\va rphi)+\sqrt{r^{2}-P^{2}\sin^{2}(\varphi)}\right)\dfrac{\mathbf{Q}}{Q }.$
• Oct 22nd 2010, 12:54 PM
EEalgorithm
I am not sure, I actually realized that I can solve everything simple enough using the law of sins. It has been so long, I forgot about them. Anyway, thanks for the help.
• Oct 22nd 2010, 12:56 PM
EEalgorithm
No looking back on your explanation, you were correct, I misunderstood your relationship between Q and R. I thought you were saying they were the same thing, but now that I look at it, I could use that method as well.
• Oct 22nd 2010, 12:59 PM
Ackbeet
You can use the law of sines, sure. It might be a little trickier to get a vector representation of everything, but I suppose it depends to some extent on exactly what information you need. Do you need a full vector representation? Or do you just want angles?