Note that there are some explanatory texts on larger screens.

plurals
  1. PO3d trigonometry equation
    text
    copied!<p>I'm trying to write a small 'perspective' javascript app that allows me to fly through a set of x,y,z points that inhabit a 3d space. </p> <p>I have the concept of a camera which changes its rotation and xyz position, while each point maintains a constant xyz point. </p> <p>I then have a set of equations that works out how the camera's x,y,z coordinates should be adjusted for flying directly forwards. The x,y,z adjustments obviously depend upon the rotation of the camera. </p> <p>It almost works, but at certain 'attitudes' the camera position adjustment goes wrong and the flightpath doesn't go straight ahead but goes off at an angle, or even reverses. The equations for working out the projection are as follows:</p> <pre><code>var directionFactor = 1; if (direction == 'backward') directionFactor = -1; sx = Math.sin(cameraView.rotX); cx = Math.cos(cameraView.rotX); sy = Math.sin(cameraView.rotY); cy = Math.cos(cameraView.rotY); sz = Math.sin(cameraView.rotZ); cz = Math.cos(cameraView.rotZ); // Z-Axis ztrig = Math.sqrt((cx * cx) + (cy * cy)) * (cx * cy); cameraView.z = cameraView.z + directionFactor * (Math.abs(airspeed / 15) * ztrig); // Y-Axis ytrig = Math.sqrt((sx * sx) + (cz * cz)) * (sx * cz); cameraView.y = cameraView.y + directionFactor * (Math.abs(airspeed / 15) *ytrig); // X-Axis xtrig = Math.sqrt((cz * cz) + (sy * sy)) * (cz * sy); cameraView.x = cameraView.x - directionFactor * (Math.abs(airspeed / 15) * xtrig); </code></pre> <p>Obviously my equations aren't quite right. Can anyone tell me where I'm going wrong? Much appreciated and thanks.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload