2d point to 3d point on a sphere - math

i haven’t been entirely sure what to google or search for to help solve my problem, really hoping someone here can help a little…
currently i have a 3d scene, it has a massive sphere with a texture mapped to it and the camera at the center of the sphere, so it’s much like a qtvr viewer.
i’d like a way to click on the polygons within the sphere and update the texture at that position with something and dot etc..
the only part of the process where i need help is converting the 2d mouse position to a point on the inside of the sphere.
hope this makes sense…
fyi, im only looking for a pure math solution..

The first thing you need to do is convert the screen coordinate into a line in 3d space. This will pass through the point you click and your eyepoint.
Once you have this line you can then intersect this line with your sphere to find the intersection point on the sphere.

You may get 2d coordinates of the polygons (triangles?) that are making up the sphere and then find the one that contains the mouse pointer point.

Related

How to calculate a random point inside a cube

I'm trying to figure out the math to find a random point inside a cube.
I have something small but it can't take into account the rotation of the cube.
Here are some images of my results.
Here you can see the cube is rotated to some degree but when I generate some points it retains the shape as if the cube was normal (I think the term is called axis aligned but I'm not sure).
I'm using a Vector to represent the extent of the cube but for the life of me I can't figure out how to get the points to follow it when it's rotated.
Can someone point me in the right direction as to how I would do this?
EDIT1:
Now its misaligned and it goes even weirder when I rotate it sideways.
Can someone walk me through it from the beginning? I think my base line math is all wrong to begin with.
Generate the points in the straight position then apply the rotation (also check the origin of the coordinates).

Calculate angle of view from 2D image

I want to calculate the angle of view (or the field of view) from a photograph, without knowing anything about the camera, as to use that information in a 3D environment.
I have to use trigonometry to solve this (most probably using arctan), but I'm not proficient enough in math ...
Can somebody please help?
Please have a look at this example.
I assume the angle between the line CENTER-LEFT and CENTER-RIGHT is 90° in reality.
I know the distances (in pixels) of point C to the vanishing points VP-left and VP-right.
Furthermore the height of the image is the angle of view in my 3D environment.
Thanks!

How to place marker inside google maps polygon

How to place marker inside polygon (this polygon already on map)?
My thoughts are: find a way to inscribe for example circle to the polygon and find a center of this circle (it is not problem), but can't find way to inscribe circle.
Method getCenter() on LatLngBounds works not as expected, because math center of polygon can be out of this polygon visually.
As said Dr.Molle this is really duplicate of this question. So, for get center of polygon need to use programm realization of anything math algorithm for find center of polygon, there is no more easy way unfortunately.

Collision detection with oddly shaped polygons

I am planning to make a program which will have some circular shapes moving inside of a oddly shaped Polygon.
I can't seem to figure out how to do the collision detection with the edges and have the shapes bounce back correctly.
I am sure this problem has been solved before, but I can't find a nice example.
My main problems are:
Figuring out if the circle has hit the edge of its surrounding polygon.
Once a hit occurs calculate the normal of the hit point to figure out the reflection vector.
Can anyone point me in the right direction?
Thanks, Jason
You need to do a circle line intersection test.
To make it faster, you can first check the bounding boxes. For example, if the start and end point of the line are both to the left of the leftmost coordinate of the circle, there can't be an intersection.

Mapping points in 2d space to a sphere

I have a bunch of points in a rectangular x/y space which I would like to project onto a sphere. As in, I am trying to write this function:
function point_on_sphere(2dx:Number, 2dy:Number) : Vector3D
{
//magic
return new Vector3D(3dx, 3dy, 3dz);
}
I have been trying to first plot the points on to a cylinder and then map those points to a sphere as directed by this wikipedia page. However, those formulas assume a constant z=0, which doesn't really do what I want.
I'm using actionscript 3 / flex, but any pseudo code or pushes in the right direction would be greatly appreciated.
Just to clarify: I'm not trying to apply a texture to a sphere object, but rather to place objects along an imaginary sphere.
There is no one right answer. You can choose different approaches based on how you want to place the objects along the sphere.
Is it OK for the objects to get nearer and nearer to each other as you get closer to the sphere's "poles"? Why wouldn't the normal texture-mapping projection actually work for you?

Resources