1

I have a sphere of radius $1$ centered on the point $(0, 0, 1)$.

I also have a point $C = (0, 0, H)$ where $0 < H < 1$ from which to project objects onto the sphere. It is located inside the lower half of the sphere, but importantly is NOT the center of the sphere OR on the surface of the sphere.

Finally, I have a point $P = (X, Y, Z)$ where $0 < Z < H$, located inside (but not at the center or surface of) the sphere, which I want to project onto the lower half of the sphere from $C$ to form the projected point $P'$.

How do I find the 3D coordinates of $P' = (X', Y', Z')$ in terms of $H$, $X$, $Y$, and $Z$?

Picture showing the setup described above in an isomorphic view

Picture showing the setup described above viewed straight down the y-axis

All the information I can find online about projecting things onto spheres assumes that the projective point is either in the center of the sphere or on the surface of the sphere, neither of which is the case for me.

Lawton
  • 1,975
  • please lookup the conversation between Cartesian co-ordinate system and spherical co-ordinate system once you get the angles correct you can draw a circle and a line below it also tilt the line by angle(thatha or phy ) then you can project those form circle to line or you can draw a squished circle – Ch.Siva Ram Kishore Dec 15 '23 at 20:26
  • @Ch.SivaRamKishore I looked it up, but I don't see how a spherical coordinate system helps me, since the projection point is not at the center of the sphere and it seems like what you are talking about requires the projection point to be the center. Am I missing something? – Lawton Dec 15 '23 at 20:51
  • May be we can move the center to (0,0,0 )the point will become (0,0,(1-Z)) – Ch.Siva Ram Kishore Dec 15 '23 at 20:57
  • @Ch.SivaRamKishore Whether we move the center of the sphere or the projective point to $(0, 0, 0)$, we still have the problem that they aren't co-located, and thus spherical coordinates don't seem to help. – Lawton Dec 15 '23 at 21:07
  • May be this post will help https://math.stackexchange.com/questions/404440/what-is-the-equation-for-a-3d-line – Ch.Siva Ram Kishore Dec 15 '23 at 21:33

3 Answers3

1

I figured out a way to do it by transforming it the 3D problem into a pair of 2D problems.

To recap, we have a sphere centered on $S = (0, 0, 1)$ with a radius of $1$; a center of projection $C = (0, 0, H)$ where $0 < H < 1$; and a point to be projected $P = (X, Y, Z)$ where $0 < Z < H$.

First, look at a cross-section of the problem in the plane defined by $S$, $C$, and $P$, with a vertical $z$-axis and a horizontal $d$-axis. In this 2D cross-section we have the simple problem of finding the intersection of a line through $C$ and $P$ with the lower-semicircle centered on $S$, where $S = (0, 1)$, $C = (0, H)$, $P = (D, Z)$, and $D = \sqrt{X^2 + Y^2}$. The equation of the semicircle is $z(d) = 1 - \sqrt{1 - d^2}$, and the equation of the line is $z(d) = H + \frac{Z - H}{D} × d$. Setting those equations equal to each other and solving for $d$ gives two answers, one negative and one positive. The one we want is the positive solution, which gives the horizontal distance of the projected point from the $z$-axis: $D' = \frac{\sqrt{(2 - H) × H × D^2 + (H - Z)^2} - (1 - H) × (H - Z)}{(H - Z)^2 + D^2} × D$. The vertical coordinate of the projected point is then easily found to be $Z' = 1 - \sqrt{1 - (D')^2}$.

enter image description here

Second, look into the plane perpendicular to the $z$-axis that passes through $P$. In this reference frame, $P = (X, Y)$. To find $X'$ and $Y'$, we simply need to divide both coordinates by $D$ to normalize them and multiply them by $D'$ to scale them to the new distance. The division by $D$ cancels with the multiplication by $D$ in $D'$, giving $X' = \frac{\sqrt{(2 - H) × H × D^2 + (H - Z)^2} - (1 - H) × (H - Z)}{(H - Z)^2 + D^2} × X$ and $Y' = \frac{\sqrt{(2 - H) × H × D^2 + (H - Z)^2} - (1 - H) × (H - Z)}{(H - Z)^2 + D^2} × Y$.

Thus,

$$ P' = \begin{pmatrix} \frac{\sqrt{(2 - H) × H × (X^2 + Y^2) + (H - Z)^2} - (1 - H) × (H - Z)}{(H - Z)^2 + (X^2 + Y^2)} × X,\\ \frac{\sqrt{(2 - H) × H × (X^2 + Y^2) + (H - Z)^2} - (1 - H) × (H - Z)}{(H - Z)^2 + (X^2 + Y^2)} × Y,\\ 1 - \sqrt{1 - \left(\frac{\sqrt{(2 - H) × H × (X^2 + Y^2) + (H - Z)^2} - (1 - H) × (H - Z)}{(H - Z)^2 + (X^2 + Y^2)} × \sqrt{X^2 + Y^2}\right)^2} \end{pmatrix} $$

Lawton
  • 1,975
0

For a sphere with centre $\mathbf{a}$ and radius $r$, the equation of the sphere is $ || \mathbf{x} - \mathbf{a} ||^2 = r^2$, and since we are projecting onto a point $P'$ that lies on the sphere, this equation holds for $\mathbf{x} = \mathbf{p}'$. On the other hand, $P'$ must lie on the line between the centre of projection $C$ and the point you are projecting $P$, so $\mathbf{p'} = \mathbf{c} + t(\mathbf{p}-\mathbf{c})$ which you may prefer to think of the linear combination $\mathbf{p'} = (1-t)\mathbf{c} + t\mathbf{p}$. When the parameter $t=0$ we are at the centre of projection $C$, when $t=1$ we are at point $P$, and if we keep moving further in that direction then $t>1$. Putting these facts together, you need to solve the quadratic equation

$$||t(\mathbf{p} - \mathbf{c}) + \mathbf{c} - \mathbf{a}||^2 = r^2$$

for $t$. Doing so will give you two values for $t$, so the problem is which value of $t$ to pick. I don't actually know the convention for projection onto a sphere (unlike a plane, the line joining the point you want to project and the centre of projection can intersect twice with the sphere you want to project onto, so which one is "the" projection?) and I have posted a Math SE question, as yet unanswered, asking precisely this point. But you seem to have a practical situation in mind, so you should use that to inform which $t$ is appropriate for your needs.

I have oriented the equation of the line so that the parameter $t$ increases as you move from the centre of projection, $\mathbf{c}$ (where $t=0$), to the point you want to project, $\mathbf{p}$ (where $t=1$). So if your application requires you to treat $\mathbf{c}$ as if it were a light source, and "cast a shadow" of $\mathbf{p}$ onto the sphere, then you reach $\mathbf{p'}$ by continuing along the line in the direction of increasing $t$, so you just need to pick the larger of your two $t$ solutions: so long as $P$ is inside the sphere, then $t$ will be a positive number greater than one. (The line will hit the sphere again at the point where $C$ casts a shadow on the sphere if you treat $P$ as a light source, but that's going "backwards" so has a negative $t$.)

If I understood correctly, you want $r=1$, the centre of the sphere at $\mathbf{a} = (0, 0, 1)^t$ and centre of projection at $\mathbf{c} = (0, 0, H)^t$ so $\mathbf{c} - \mathbf{a} = (0, 0, H-1)^t$ and the squared distance between the two centres is $||\mathbf{c} - \mathbf{a}||^2 = (H-1)^2$. Similarly the squared distance between the point $P$ and the centre of projection is $||\mathbf{p} - \mathbf{c}||^2 = X^2 + Y^2 + (Z-H)^2$. Finally, we note that the scalar product of $\mathbf{c} - \mathbf{a}$ with $\mathbf{p} - \mathbf{c}$ is $(0, 0, H-1)^t \cdot (X, Y, Z-H) = (H-1)(Z-H)$. If we expand our equation for $t$ so we can more easily see the quadratic coefficients:

\begin{align} \left( t(\mathbf{p} - \mathbf{c}) + \mathbf{c} - \mathbf{a} \right) \cdot \left( t(\mathbf{p} - \mathbf{c}) + \mathbf{c} - \mathbf{a} \right) &= r^2 \\ \implies ||\mathbf{p} - \mathbf{c}||^2 t^2 + 2(\mathbf{c} - \mathbf{a}) \cdot (\mathbf{p} - \mathbf{c}) t + ||\mathbf{c} - \mathbf{a}||^2 - r^2 &= 0 \\ \implies (X^2 + Y^2 + (Z-H)^2)t^2 + 2(H-1)(Z-H)t + (H-1)^2 - 1 &= 0 \end{align}

These coefficients can then be substituted into the quadratic formula $t = \frac{-b \pm \sqrt{b^2 - 4ac}}{2a}$. It comes out slightly nicer if we notice the constant term is $H^2 - 2H = H(H-2)$ and we divide the quadratic equation by two because of the factor of two in front of the $t$ term:

\begin{align} t &= \frac{-(H-1)(Z-H) \pm \sqrt{(H-1)^2(Z-H)^2 - H(H-2)(X^2 + Y^2 + (Z-H)^2)}}{X^2 + Y^2 + (Z-H)^2} \\ \implies t &= \frac{(1-H)(Z-H) \pm \sqrt{(Z-H)^2 - H(H-2)(X^2 + Y^2)}}{X^2 + Y^2 + (Z-H)^2} \\ \implies t &= \frac{\pm \sqrt{H(2-H)(X^2 + Y^2) + (Z-H)^2} - (1-H)(H-Z)}{X^2 + Y^2 + (Z-H)^2} \end{align}

where I've tried rearranging to make it look more like your result. If I understand your practical objective correctly, you want the positive square root so that $t$ corresponds to the point on the sphere you reach if you move in the direction from $C$ to $P$. Finally, once you solved numerically for $t$, you can find the coordinates of $P'$ by substituting into $\mathbf{p'} = \mathbf{c} + t(\mathbf{p}-\mathbf{c})$:

\begin{align} (X', Y', Z') = (0, 0, H)^t + t(X, Y, Z - H)^t \\ \implies \begin{cases} X' &= Xt \\ Y' &= Yt \\ Z' &= (Z - H)t + H \end{cases} \end{align}

If you were doing for this for many points $P$, but wanted to keep the centre of projection $C$ and centre $A$ and radius $r$ of the sphere fixed, then you could:

  • pre-compute and store $\mathbf{c} - \mathbf{a}$ and $||\mathbf{c} - \mathbf{a}||^2 - r^2$ so they don't need to be recalculated for each point $P$,
  • for each $P$, find $\mathbf{p} - \mathbf{c}$ and hence $||\mathbf{p} - \mathbf{c}||^2$ and $(\mathbf{c} - \mathbf{a}) \cdot (\mathbf{p} - \mathbf{c})$,
  • solve $||\mathbf{p} - \mathbf{c}||^2 t^2 + 2(\mathbf{c} - \mathbf{a}) \cdot (\mathbf{p} - \mathbf{c}) t + ||\mathbf{c} - \mathbf{a}||^2 - r^2 = 0$ for $t$, and for your application taking the larger, positive root (you might not want to do this by the conventional quadratic formula, see here, here and here),
  • substitute your $t$ into $X' = Xt$, $Y' = Y$ and $Z' = (Z - H)t + H$.

This should be substantially faster than using big nasty formulas for $X'$, $Y'$ and $Z'$ separately — the gnarly bit really only needs to be computed once per point $P$, and some parts don't need to be recomputed at all if $A$, $C$ and $r$ are fixed.

Silverfish
  • 1,871
-1

enter image description here

Hint: As shown in the figure, in plane geometry , the projection of a point on the circle is where the line connecting the point and center of the circle ,$l$,intersects the circle. In solid geometry it is the intersection of $l$ and sphere.You have to solve following system of equations:

$\begin{cases}x^2+y^2+z^2=r^2;( equation ,of, the, sphere).\\\frac{x-x_O}{x_c-x_O}=\frac{y-y_O}{y_c-y_O}=\frac{z-z_O}{z_c-z_O}=t(equation, of, the, line \end{cases}$

Where C is the point to be projected and O is the center of the sphere.

Find x, y and z in terms of $t$, then put these in the equation of the sphere, you will find an equation of degree 2 in terms of $t$. Solve this equation and find the value of $t$, put this in the equation of the line and find the coordinates of projection of C(or P) on the sphere.You can use this rule for both cases.

$\frac{x-x_O}{x_c-x_O}=t$

$\frac{y-y_O}{y_c-y_O}=t$

$\frac{z-z_O}{z_c-z_O}=t$

In your case we have:

$(x_O, y_O, z_O)=(0, 0, 1)$

$(x_C, y_C, z_C)=(0, 0, H)$

$(x_P, y_P, z_P)=(X, Y, Z)$

sirous
  • 12,694
  • 1
    If my understanding of the figure you provide and the text of your answer is correct, you are projecting from the center of the sphere. However, in my case the line of projection does NOT pass through the center of the sphere. Am I misinterpreting your answer? – Lawton Dec 16 '23 at 13:33
  • Your understanding is correct. I cannot imagine the projection of a point on a circle or sphere is not through their centers. Do you know any reference to show that, maybe I am not aware of. thanks. – sirous Dec 16 '23 at 18:42
  • 1
    That's what I'm asking for in my question. I included two pictures showing the setup. As I say, all I can find is information on how to project from the center of the sphere or from the pole of the sphere. However, I want to project from a point that is between the center and surface of the sphere, rather than at either extreme. – Lawton Dec 16 '23 at 19:05
  • makes no difference where the point is located. Due to the definition of projection, it is the foot or intersection of a line passing the point and perpendicular on a surface. Hence you must have the equation of the line anyway.For this you need the know the coordinates of at least two points. You just have this for one point P. – sirous Dec 16 '23 at 20:35