How to project a point on to a sphere - geometry

If i have a point (x,y,z) how to project it on to a sphere(x0,y0,z0,radius) (on its surface).
My input will be the coordinates of point and sphere.
The output should be the coordinates of the projected point on sphere.
Just convert from cartesian to spherical coordinates?

For the simplest projection (along the line connecting the point to the center of the sphere):
Write the point in a coordinate system centered at the center of the sphere (x0,y0,z0):
P = (x',y',z') = (x - x0, y - y0, z - z0)
Compute the length of this vector:
|P| = sqrt(x'^2 + y'^2 + z'^2)
Scale the vector so that it has length equal to the radius of the sphere:
Q = (radius/|P|)*P
And change back to your original coordinate system to get the projection:
R = Q + (x0,y0,z0)

Basically you want to construct a line going through the spheres centre and the point. Then you intersect this line with the sphere and you have your projection point.
In greater detail:
Let p be the point, s the sphere's centre and r the radius then x = s + r*(p-s)/(norm(p-s)) where x is the point you are looking for. The implementation is left to you.
I agree that the spherical coordinate approach will work as well but is computationally more demanding. In the above formula the only non-trivial operation is the square root for the norm.

It works if you set the coordinates of the center of the sphere as origin of the system (x0, y0, z0). So you will have the coordinates of the point referred to that origin (Xp', Yp', Zp'), and converting the coordinates to polar, you discard the radius (distance between the center of the sphere and the point) and the angles will define the projection.

Related

Having the coordinates of the two triangles of a twisted triangle prism, how can I know if a point is inside it?

Here some examples of twisted triangle prisms.
I want to know if a moving triangle will hit a certain point. That's why I need to solve this problem.
The idea is that a triangle with random coordinates becomes the other random triangle whose vertices all move between then
related: How to determine point/time of intersection for ray hitting a moving triangle?
One of my students made this little animation in Mathematica.
It shows the twisting of a prism to the Schönhardt polyhedron.
See the Wikipedia page for its significance.
It would be easy to determine if a particular point is inside the polyhedron.
But whether it is inside a particular smooth twisting, as in your image, depends on the details (the rate) of the twisting.
Let's bottom triangle lies in plane z=0, it has rotation angle 0, top triangle has rotation angle Fi. Height of twisted prism is Hgt.
Rotation angle linearly depends on height, so layer at height h has rotation angle
a(h) = Fi * h / Hgt
If point coordinates are (x,y,z), then shift point to z=0 and rotate (x,y) coordinates about rotation axis (rx, ry) by -a(z) angle
t = -a(z) = - Fi * z / Hgt
xn = rx + (x-rx) * Cos(t) - (y-ry) * Sin(t)
yn = ry + (x-rx) * Sin(t) - (y-ry) * Cos(t)
Then check whether (xn, yn) lies inside bottom triangle

Outline of a sphere after perspective projection?

I'm working on a 3D mapping application, and I've got to do some work with things like figuring out the visible region of a sphere (Earth) from a given point in space for things like clipping mapped regions and such.
Several things get easier if I can project the outline of Earth into screen space, clip polygons there, and then project back to the surface of the Earth (lat/lon), but I'm lost as to how to do that.
Is there a reasonable way to compute the outline of a sphere after perspective projection, and then a reasonable way to project things back onto the sphere?
You can clip the polygons in 3D. The silhouette of the sphere - back-projected into 3D - will always be a circle on a plane. Perspective projection does not change that. Thus, you can clip all polygons at the plane.
Calculating the plane is not too hard. If you consider the sphere's center the origin, then the plane could be represented in normal form as:
dot(n, x) = d
n is the normal. This one is easy. It is just the unit direction vector from the sphere center to the observer.
d is the distance from the sphere center. This is a bit harder but not too hard. If l is the distance of the observer to the sphere center and r is the sphere radius, then
d = r^2 / l
This is the plane which you can use to clip your polygons in 3D. If you need the radius of the circle on it, you can use the following formula:
r_c = r / sqrt(1 - r^2/(l-d)^2)
Let us take a point on a sphere in spherical coordinates (cos(u)sin(v),sin(u)sin(v),cos(v)) and an arbitrary projection center (x,y,z).
We express that a projecting line is tangent to the sphere by the perpendicularity condition of the direction of the line and the vector from the origin of the sphere:
(x-cos(u)sin(v))cos(u)sin(v) + (y-sin(u)sinv))sin(u)sin(v) + (z-cos(v)) cos(v) = 0
This simplifies to
x cos(u)sin(v) + y sin(u)sin(v) + z cos(v) = 1
which is a curve in the longitude/latitude coordinates. You can solve u as a function of v or conversely.

Geometry of a radial coordinate to Cartesian with bounding points

I need to find 4 points in Latitude/Longitude format surrounding a given center point and a resulting algorithm (if possible).
Known information:
Equal distances for each "bin" from center of point (Radar) outward.
Example = .54 nautical miles.
1 Degree beam width.
Center point of the "bin"
This image is in Polar coordinates (I think this is similar to Radial coordinates???):
I need to convert from Polar/Radial to Cartesian and I should be able to do that with this formula.
x = r × cos( θ )
y = r × sin( θ )
So now all I need to do is find the "bin" outline coordinates (4 corners) so I can draw a polygon in a Cartesian coordinate space.
I'm using Delphi/Pascal for coding, but I might be able to convert other languages if you have a sample algorithm.
Thanks for any suggestions or sample algorithms.
Regards,
Bryan
You need to convert everything to the same coordinate system and then impose the distance criteria as follows:
Convert your center point from geographic coordinates to polar coordinates to yield (rC, θC)
Convert your center point from polar to Cartesian coordinates using your equations yielding (xC, yC)
The corner points on the right side of the center points (xR, yR) satisfy the equation
(xR - xC)2 + (yR - yC)2 = D2
[rRcos(θC+0.5o) - xC]2 + [rRsin(θC+0.5o) - yC]2 = D2
where D=distance between the center point and corner points
Everything is known in the above equation except rR. This should yield a quadratic equation with two solutions which you can easily solve. Those are your two corner points on the right side.
Repeat step 3 with angle θC-0.5o to get the corner points on the left side.

Find a coordinate along a path

My trigonometry needs a little help.
How would I go about calculating the point of the nearest possible intersection with a line along a rounded corner?
Take this image:
What I would like to know is, given that I know point a, and the dimensions of the rectangle, how would I find point b when the edges of the rectangle are curved?
So far, as you can see, I've only managed to calculate the nearest edge of the rectangle as if it had right-angled corners.
If it matters, I'm doing this in ActionScript 3. But example sudo-code will suffice.
Calculate the vector from the midpoint M of the corner to A:
v_x = a_x - m_x
v_y = a_y - m_y
then go radius of the corner r times towards A to get to the intersection point I
i_x = m_x + r*v_x
i_y = m_y + r*v_y
This obviously only works if the nearest intersection is on the rounded corner. Just calculate the other intersections with the edges, too, and then check which has the nearest distance to A.
You need to know the radius R of the circle that generates the round corner and the coordinates (Xr,Yr) of the point where the two sides of a non rounded rectangle cross each other.
Then the coordinates for the center of the circle that generates the round corner are (Xc, Yc) = (Xr-R, Yr-R)
From here, it's a matter of solving the equation of the cross point between the segment line defined by point A=(Xa, Ya) and point (Xc, Yc), whose parametric equation is:
x = Xa + p*(Xc-Xa)
y = Ya + p*(Yc-Ya)
and the circle whose equation is
(x-Xc)^2 + (y-Yc)^2 = R^2
Substitute values for x and y from the parametric euation of the line in the equation of the circle, and you will have an equation with only one unkown: p. Solve the equation, and if there are more than one solution, choose the one that is in the range [0,1]. Substitute the found value of p in the parametric equation of the line to get the point of intersection.
Graphically:
If you know the radius and center of the corner as R and C=(Xc, Yc), then the nearest point on the corner to the given point A=(Xa, Ya) is the intersection point of the corner and the line defined by the given point and the center. This point can be directly expressed as
X = Xc + R*(Xa-Xc)/|AC|
Y = Yc + R*(Ya-Yc)/|AC|
where |AC| = Sqrt((Xa-Xc)^2 + (Ya-Yc)^2)

Convert 3D(x,y,z) to 2D(x,y) (orthogonal) along its direction

I have gone through all available study resources in the internet as much as possible, which are in form of simple equations, vectors or trigonometric equations.
I couldn't find the way of doing following thing:
Assuming Y is up in a 3D world.
I need to draw two 2D trajectories orthogonally (not the projections) for a 3D trajectory, say XY-plane for side view of the trajectory w.r.t. the trajectory itself and XZ-plane for top view for the same.
I have all the 3D points of the 3D trajectory, initial velocity, both the angles can be calculated by vector mathematics.
How should I proceed further?
refer:
Below a curve in different angles, which can loose its significance if projected along XY-plane. All I want is to convert the red curve along itself, the green curve along green curve and so on. and further how would I map side view to a plane. Top view is comparatively easy and done just by taking X and Z ordinates of each points.
I mean this the requirement. :)
I don't think I understand the question, but I'll answer my interpretation anyway.
You have a 3D trajectory described by a sequence of points p0, ..., pN. We are given an angle v for a plane P parallel to the Y-axis, and wish to compute the 2D coordinates (di, hi) of the points pi projected onto that plane, where hi is the height coordinate in the direction Y and di is the distance coordinate in the direction v. Assume p0 = (0, 0, 0) or else subtract p0 from all vectors.
Let pi = (xi, yi, zi). The height coordinate is hi = yi. Assume the angle v is given relative to the Z-axis. The vector for the direction v is then r = (sin(v), 0, cos(v)), and the distance coordinates becomes di = dot(pi, r).

Resources