ThreeJS. Intersection between Ray and plane Z (z=0) - three.js

Each Raycaster Ray object has an origin and a direction (raycaster.ray).
What I want is find intersection between a ray and the plane in which all points have z = 0 (z plane).
To create a proper plane and then using raycaster on it is not a solution.
I would know what is the best way to find this intersection.

Related

Projecting Sphere to Rectangle/Square using Mercerator Projection

I am learning some projection technique where we can project a 3d object like globe to a 2d. I have the 3d coordinates of points on the surface of sphere same as globe. Here is a reference where a globe can be projected on a plane using Stereo-graphic projection (https://en.wikipedia.org/wiki/Stereographic_projection) but this projection project the globe to a circle but i am trying to project sphere to a rectangle the same way as the globe is projected on a small paper (https://en.wikipedia.org/wiki/Mercator_projection).
For any projection, you're going to need to construct a map (no pun intended) from one coordinate system to the other.
For the mercator projection, the map can be a function of your sphere coordinate (azimuth & elevation) to rectangular coordinate (x & y).
Azimuth is your x coordinate. Elevation is your y coordinate.

Raycast to find point that intersects the z-axis at zero

Is it possible to make a raycast that triggers when it intersects zero on the z-axis, rather than waiting to hit an object?
I have an orthographic camera at (0, 0, -40), and facing directly towards the origin. I want to send a raycast from the center of each edge of the camera's viewport to find the (x, y) points where they intersect the z-axis at zero.
If it's an orthographic camera, the edges of the frustum are parallel like a box. Looking straight down the Z-axis, you can get the x,y values easily with:
x: camera.left or camera.right
y: camera.top or camera.bottom
They don't diverge at all, since ortho cams don't have perspective, so they'll also cross the Z-plane at the position of the camera's edges.

Quaternion for camera rotation

I have an up vector , position vector of the camera and position vector of the object the camera needs to be looking at. Is it possible to compute the quaternion based on this information? How can I do that ?
I tried this -
I thought the camera (at A) is by default looking in direction given by up vector(U). From there it needs to turn towards the object(B). Therefore final direction will be B-A. So I compute the angle and axis of rotation from U to B-A. But that doesn't give the right answer.

Three.js - sending ray from object to camera

Thanks for the helps in advance.
Three.js Raycaster class allows sending rays from camera to the object. I want to achieve a reverse operation. Imagine that we have a plane in the scene which represents our screen for projection. We also have an object (mesh) to be projected. I'm trying to find where would a vertex be projected on the screen.
Practically, for a vertex, if we project a ray from vertex to camera, we need to find its intersection with the screen plane. Note that everything is in 3D here. So my screen(camera) plane is in 3D coordinates too.
Any advise to solve this problem?
I think what you are looking for is projection of an object3d to screen position.
It was answered here:
answer
then you will have vector2d with x,y screen coordinates.
if you want the point on an actual 3d plane, you can then make a ray from the camera to that position on the screen, add to the ray intersection only that plane you locate infront of the camera, and then get the intersection point:
rayCaster.setFromCamera(vector2d, camera);
var aIntersects = rayCaster.intersectObject(planeInFrontOfCamera);
if (aIntersects.length > 0) {
var positionOnPlane = aIntersects[0].point.
}

How to find whether a point in a 3D space lies inside a hemisphere?

Tip of the hemisphere - (x,y2,z)
Mid point of the circle in the hemisphere - (x,y,z)
As x,y,z and y2 can be anywhere in the 3D space, the hemisphere could point any direction and so I am struggling with the direction part. I can't solve this similar to a cone, sphere or a truncated cone.
Let us call your point (a,b,c). Note that a hemisphere is the intersection of a half-space and a sphere. So we just test intersection with both and AND the result. First test whether the point is on the right side of the half-space:
dy = y2-y;
if (b-y)*dy<0 then
return no intersection
This uses the fact that the distance of the tip to the center will have a different sign than the distance of the point to the center only if the test point is in the wrong half-space.
Then check versus the sphere. This is inferred from the distance of the tip to the center:
squareDistance = (x-a)²+(y-b)²+(z-c)²;
if squareDistance > dy² then
return no intersection
else
return intersection

Resources