Re: [pointerevents] add altitudeAngle/azimuthAngle (#316)

I did the trig math for altitude/azimuth so please have a look. Let me know if I made mistakes. 

If pen's tip is resting at `(x0, y0, 0)` and let's say the length of the pen is `L=sqrt(a^2+b^2+c^2)` then the pen is spatially fully described by its tip `(x0, y0, 0)` and cap `(a+x0, b+y0, c)`. 

Now we can compute `tiltX`, `tiltY`, `altitude` and `azimuth` in terms of `a`,`b`,`c`. The terms `x0`,`y0` do not matter as they are not participating in computing distances. `x0`, `y0` will not appear going forward.

`TiltX` angle is described by the angle between normals to the planes `(pen, Y)` and `(Y,Z)`: `N(pen,Y) = (-c, 0, a)` and `N(Y,Z)=(-1, 0, 0)`. Which gives us:
```
cos(tiltX)=c/sqrt(a^2+c^2) 
sin(tiltX)=a/sqrt(a^2+c^2)
tan(tiltX)=a/c
```
`TiltY` angle is described by the angle between normals to the planes `(pen, X)` and `(X,Z)`: `N(pen,X)=(0,c,-b)`, `N(X,Z)=(0,1,0)`. Which gives us:
```
cos(tiltY)=c/sqrt(b^2+c^2)
sin(tiltY)=b/sqrt(b^2+c^2)
tan(tiltY)=b/c
```
`Altitude` is the angle between the vector `(a,b,c)` and plane `(X,Y)` described by angle between vectors `(a,b,c)` and `N(X,Y) = (0,0,1)`. Which gives us:
```
cos(altitude)=sqrt(a^2+b^2)/sqrt(a^2+b^2+c^2)
sin(altitude)=c/sqrt(a^2+b^2+c^2)
tan(altitude)=c/sqrt(a^2+b^2)
``` 
`Azimuth` is the angle between the projection of the pen on `(X,Y)` plane and the `X` axis. The projection of the pen has vector `(a,b,0)`, the `X` axis has vector `(1,0,0)`. Which gives us:
```
sin(azimuth)=b/sqrt(a^2+b^2)
cos(azimuth)=a/sqrt(a^2+b^2)
tan(azimuth)=b/a
``` 
Having the above formulas it is easy to verify the formulas at https://github.com/jquery/PEP/pull/376/files#diff-3b5aeb16d85e265fdb40c6063ac62a96R160 to be correct:
```
tiltX=Math.atan(Math.cos(azimuth) / Math.tan(altitude)) * radToDeg
tiltY=Math.atan(Math.sin(azimuth) / Math.tan(altitude)) * radToDeg
```
For computing `azimuth` and `altitude` from `tiltX` and `tiltY` we can easily compute `a` and `b` in terms of `c` from `tan(tiltY)=b/c` and `tan(tiltX)=a/c` and then substitute in formula's for `azimuth` and `altitude`.
```
azimuth=arctan(tan(tiltY)/tan(tiltX))
altitude=arctan(1/sqrt(tan^2(tiltX)+tan^2(tiltY))) - one way to compute it there's probably other ways
```
[1] https://www.w3.org/TR/pointerevents3/
[2] https://w3c.github.io/touch-events/
[3] https://www.analyzemath.com/stepbystep_mathworksheets/vectors/vector3D_angle.html
[4] https://onlinemschool.com/math/library/analytic_geometry/plane_angl/

-- 
GitHub Notification of comment by liviutinta
Please view or discuss this issue at https://github.com/w3c/pointerevents/pull/316#issuecomment-606765923 using your GitHub account

Received on Tuesday, 31 March 2020 17:27:17 UTC