question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Get 3d coordinates from 2d point

See original GitHub issue

Hi guys

I would like to know how can i get the 3d coordinates from a collision point mouse 2d from this code

function onDocumentMouseDown( event ) {
   event.preventDefault();
   mouse2d.x = ( event.clientX / window.innerWidth ) * 2 - 1;
   mouse2d.y = - ( event.clientY  / window.innerHeight ) * 2 + 1;
   mouse2d.z = 1;

   var r = new THREE.Ray();
   r.origin.copy( mouse2d );
   var matrix = camera.matrixWorld.clone();
   matrix.multiplySelf( THREE.Matrix4.makeInvert( camera.projectionMatrix ) );
   matrix.multiplyVector3( r.origin );
   r.direction = r.origin.clone().subSelf( camera.position );
   var c = THREE.Collisions.rayCastNearest( r );
   if( c ) {
//////////////////HERE GET THE 3D POINT COORDINATES////////////////////////
      c.mesh.materials[ 0 ].color.setHex( 0xaa0000 );
   } else {
      plane.materials[0].color.setHex( 0xF9EFD7 );
   }
};

The collision object is a plane which i use as ground and i want to know the collision point 3d coords in order to set an object’s position. Thanks in advance

Issue Analytics

  • State:closed
  • Created 12 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

5reactions
baggcommented, Jul 1, 2011

Never mind found it

0reactions
halay08commented, May 30, 2017
var getZvalue = function (e)
{
	var rect = e.target.getBoundingClientRect();
	// 2D
	var mouseX = e.clientX - rect.left;
	var mouseY = e.clientY - rect.top;

	// 3D
	SCREEN_WIDTH = window.innerWidth;
	SCREEN_HEIGHT= window.innerHeight;
	var mouse = new THREE.Vector2();
	mouse.x = (mouseX/SCREEN_WIDTH) *2 - 1;
	mouse.y = -(mouseY/SCREEN_HEIGHT) *2 + 1;

	// Raycaster
	if (TerraDroneViewer.raycaster == null)
	{
		TerraDroneViewer.raycaster = new THREE.Raycaster();
	}

	TerraDroneViewer.raycaster.setFromCamera( mouse, TerraDroneViewer.camera );

	var intersects = TerraDroneViewer.raycaster.intersectObjects( TerraDroneViewer.maps.children );
	console.log("raycast=" + intersects.length);

	if (intersects.length != 0)
	{
		var x = mouse.x * 10;
		var y = mouse.y * 10;
		console.log("x = " + intersects[0].point.x + " y = " + intersects[0].point.y);
		var z = parseFloat(intersects[0].point.z) * 10;

		return {
                     x: x,
                     y: y,
                     z: z
                }
	}

        return null;
};
Read more comments on GitHub >

github_iconTop Results From Across the Web

How to get 3D point coordinates from a 2D point? - Reddit
Use cv2.recoverPose to get the triangulated 3d points. You can refer to the OpenCV docs, go to the cv2.recoverpose section.
Read more >
Computing the Pixel Coordinates of a 3D Point (Mathematics ...
Note that pixels too are 2D points, only their coordinates are integers and the coordinate system these coordinates refer to is located in...
Read more >
How do I reverse-project 2D points into 3D? - Stack Overflow
Projecting each of these 3D coordinates into 2D is done by multiplying the 4D vector [x, y, z, 1] with a 4x4 projection...
Read more >
3d coordinate from 2d pixel coordinate · Issue #3 - GitHub
I tried calculating the 3d world coordinates from 2d pixel coordinates using the estimated homography using the provided code. Here is the small ......
Read more >
How can I convert 3D world coordinates to 2D image ...
The ZED SDK provides also the point cloud, providing 3D and RGB information for each pixel (u,v). What are the formulas to get...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found