MCPcopy Index your code
hub / github.com/plotly/plotly.js / unRoll

Function unRoll

src/plots/geo/zoom.js:362–402  ·  view source on GitHub ↗
(rotateAngles, pt, lastRotate)

Source from the content-addressed store, hash-verified

360// note that this doesn't depend on the particular projection,
361// just on the rotation angles
362function unRoll(rotateAngles, pt, lastRotate) {
363 // calculate the fixed point transformed by these Euler angles
364 // but with the desired roll undone
365 var ptRotated = rotateCartesian(pt, 2, rotateAngles[0]);
366 ptRotated = rotateCartesian(ptRotated, 1, rotateAngles[1]);
367 ptRotated = rotateCartesian(ptRotated, 0, rotateAngles[2] - lastRotate[2]);
368
369 var x = pt[0];
370 var y = pt[1];
371 var z = pt[2];
372 var f = ptRotated[0];
373 var g = ptRotated[1];
374 var h = ptRotated[2];
375
376 // the following essentially solves:
377 // ptRotated = rotateCartesian(rotateCartesian(pt, 2, newYaw), 1, newPitch)
378 // for newYaw and newPitch, as best it can
379 var theta = Math.atan2(y, x) * degrees;
380 var a = Math.sqrt(x * x + y * y);
381 var b;
382 var newYaw1;
383
384 if(Math.abs(g) > a) {
385 newYaw1 = (g > 0 ? 90 : -90) - theta;
386 b = 0;
387 } else {
388 newYaw1 = Math.asin(g / a) * degrees - theta;
389 b = Math.sqrt(a * a - g * g);
390 }
391
392 var newYaw2 = 180 - newYaw1 - 2 * theta;
393 var newPitch1 = (Math.atan2(h, f) - Math.atan2(z, b)) * degrees;
394 var newPitch2 = (Math.atan2(h, f) - Math.atan2(z, -b)) * degrees;
395
396 // which is closest to lastRotate[0,1]: newYaw/Pitch or newYaw2/Pitch2?
397 var dist1 = angleDistance(lastRotate[0], lastRotate[1], newYaw1, newPitch1);
398 var dist2 = angleDistance(lastRotate[0], lastRotate[1], newYaw2, newPitch2);
399
400 if(dist1 <= dist2) return [newYaw1, newPitch1, lastRotate[2]];
401 else return [newYaw2, newPitch2, lastRotate[2]];
402}
403
404function angleDistance(yaw0, pitch0, yaw1, pitch1) {
405 var dYaw = angleMod(yaw1 - yaw0);

Callers 1

zoomClippedFunction · 0.85

Calls 2

rotateCartesianFunction · 0.85
angleDistanceFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…