Continuing the discussion from How to limit pan in OrbitControls for OrthographicCamera?:

The solution explained here works as expected but I would like to take it a step further the boundary to be elliptical.

Continuing the discussion from How to limit pan in OrbitControls for OrthographicCamera?:

The solution explained here works as expected but I would like to take it a step further the boundary to be elliptical.

I figured it out. Here’s the general idea for anyone interested:

```
document.addEventListener("mousemove", (event) => {
var dx = (whereverYourXIs - event.clientX)
var dy = (whereverYourYIs - event.clientY)
var alpha = (Math.atan2(dy, -dx) * 180 / Math.PI + 360) % 360
var maxX = Math.abs(yourXRadius * (Math.cos(alpha / 180 * Math.PI)))
var maxY = Math.abs(yourYRadius * (Math.sin(alpha / 180 * Math.PI)))
dx = Math.min(Math.max(-maxX, dx), maxX)
dy = Math.min(Math.max(-maxY, dy), maxY)
camera.position.x = -dx + whereverYourXIs
camera.position.y = dy + whereverYourYIs
}
```