# Convert 2D mouse coordinates to 3D

**URL:** https://discourse.threejs.org/t/convert-2d-mouse-coordinates-to-3d/4989
**Category:** Questions
**Tags:** math
**Created:** [November 18, 2018, 9:42pm UTC](https://discourse.threejs.org/t/convert-2d-mouse-coordinates-to-3d/4989 "2018-11-18T21:42:43Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![aitheorem](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/aitheorem/32/17994_2.png) [@aitheorem](https://discourse.threejs.org/u/aitheorem)
#### Post date: [November 18, 2018, 9:42pm UTC](https://discourse.threejs.org/t/convert-2d-mouse-coordinates-to-3d/4989/1 "2018-11-18T21:42:43Z")

</div>

I would like to know how to obtain the correct 2D coordinates from the mouse and then how to convert those coordinates to 3D. I really appreciate any help.

---

<div class="post-metadata">

### Author: ![prisoner849](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/prisoner849/32/535_2.png) [@prisoner849](https://discourse.threejs.org/u/prisoner849)
#### Post date: [November 18, 2018, 9:51pm UTC](https://discourse.threejs.org/t/convert-2d-mouse-coordinates-to-3d/4989/2 "2018-11-18T21:51:44Z")

</div>

Hi!  
Could you clarify, what you try to achieve?

---

<div class="post-metadata">

### Author: ![danlong](https://avatars.discourse-cdn.com/v4/letter/d/58f4c7/32.png) [@danlong](https://discourse.threejs.org/u/danlong)
#### Post date: [November 19, 2018, 9:34am UTC](https://discourse.threejs.org/t/convert-2d-mouse-coordinates-to-3d/4989/3 "2018-11-19T09:34:43Z")

</div>

You should look at the Three.js Raycaster class. This can transform your 2D mouse click in to a 3D world position. [https://threejs.org/docs/#api/en/core/Raycaster](https://threejs.org/docs/#api/en/core/Raycaster)

The example code on that page is a good starting point.

---

<div class="post-metadata">

### Author: ![aitheorem](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/aitheorem/32/17994_2.png) [@aitheorem](https://discourse.threejs.org/u/aitheorem)
#### Post date: [November 19, 2018, 2:19pm UTC](https://discourse.threejs.org/t/convert-2d-mouse-coordinates-to-3d/4989/4 "2018-11-19T14:19:33Z")

</div>

Thank you very much, I will look at Raycaster.

---

<div class="post-metadata">

### Author: ![aitheorem](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/aitheorem/32/17994_2.png) [@aitheorem](https://discourse.threejs.org/u/aitheorem)
#### Post date: [November 19, 2018, 2:37pm UTC](https://discourse.threejs.org/t/convert-2d-mouse-coordinates-to-3d/4989/5 "2018-11-19T14:37:46Z")

</div>

Very perceptive, I 'm trying to determine if there is a bug with this example: [https://threejs.org/examples/misc\_boxselection.html](https://threejs.org/examples/misc_boxselection.html). I understand that there is a bug with the event variable (which I have fixed in my development environment).

Since I’m not sure where the problem is, I figured I would start at the beginning (mouse mathematics) and work my way through the end (camera mathematics). The issue is after the following lines are executed:

```
vecTopLeft.unproject(this.camera);
vecTopRight.unproject(this.camera);
vecDownRight.unproject(this.camera);
vecDownLeft.unproject(this.camera);

```

The coordinates are nowhere near the region that was selected. Additionally, the variable names represent the locations of the points used to form a quadrilateral. After the conversion from 2D to 3D, the variable names no longer match their positions.
