|
Last change
on this file since e4c61dd was e4c61dd, checked in by istevanoska <ilinastevanoska@…>, 6 months ago |
|
Prototype 1.1
|
-
Property mode
set to
100644
|
|
File size:
1.6 KB
|
| Line | |
|---|
| 1 | var epsilon2 = 1e-12;
|
|---|
| 2 |
|
|---|
| 3 | function cosh(x) {
|
|---|
| 4 | return ((x = Math.exp(x)) + 1 / x) / 2;
|
|---|
| 5 | }
|
|---|
| 6 |
|
|---|
| 7 | function sinh(x) {
|
|---|
| 8 | return ((x = Math.exp(x)) - 1 / x) / 2;
|
|---|
| 9 | }
|
|---|
| 10 |
|
|---|
| 11 | function tanh(x) {
|
|---|
| 12 | return ((x = Math.exp(2 * x)) - 1) / (x + 1);
|
|---|
| 13 | }
|
|---|
| 14 |
|
|---|
| 15 | export default (function zoomRho(rho, rho2, rho4) {
|
|---|
| 16 |
|
|---|
| 17 | // p0 = [ux0, uy0, w0]
|
|---|
| 18 | // p1 = [ux1, uy1, w1]
|
|---|
| 19 | function zoom(p0, p1) {
|
|---|
| 20 | var ux0 = p0[0], uy0 = p0[1], w0 = p0[2],
|
|---|
| 21 | ux1 = p1[0], uy1 = p1[1], w1 = p1[2],
|
|---|
| 22 | dx = ux1 - ux0,
|
|---|
| 23 | dy = uy1 - uy0,
|
|---|
| 24 | d2 = dx * dx + dy * dy,
|
|---|
| 25 | i,
|
|---|
| 26 | S;
|
|---|
| 27 |
|
|---|
| 28 | // Special case for u0 ≅ u1.
|
|---|
| 29 | if (d2 < epsilon2) {
|
|---|
| 30 | S = Math.log(w1 / w0) / rho;
|
|---|
| 31 | i = function(t) {
|
|---|
| 32 | return [
|
|---|
| 33 | ux0 + t * dx,
|
|---|
| 34 | uy0 + t * dy,
|
|---|
| 35 | w0 * Math.exp(rho * t * S)
|
|---|
| 36 | ];
|
|---|
| 37 | }
|
|---|
| 38 | }
|
|---|
| 39 |
|
|---|
| 40 | // General case.
|
|---|
| 41 | else {
|
|---|
| 42 | var d1 = Math.sqrt(d2),
|
|---|
| 43 | b0 = (w1 * w1 - w0 * w0 + rho4 * d2) / (2 * w0 * rho2 * d1),
|
|---|
| 44 | b1 = (w1 * w1 - w0 * w0 - rho4 * d2) / (2 * w1 * rho2 * d1),
|
|---|
| 45 | r0 = Math.log(Math.sqrt(b0 * b0 + 1) - b0),
|
|---|
| 46 | r1 = Math.log(Math.sqrt(b1 * b1 + 1) - b1);
|
|---|
| 47 | S = (r1 - r0) / rho;
|
|---|
| 48 | i = function(t) {
|
|---|
| 49 | var s = t * S,
|
|---|
| 50 | coshr0 = cosh(r0),
|
|---|
| 51 | u = w0 / (rho2 * d1) * (coshr0 * tanh(rho * s + r0) - sinh(r0));
|
|---|
| 52 | return [
|
|---|
| 53 | ux0 + u * dx,
|
|---|
| 54 | uy0 + u * dy,
|
|---|
| 55 | w0 * coshr0 / cosh(rho * s + r0)
|
|---|
| 56 | ];
|
|---|
| 57 | }
|
|---|
| 58 | }
|
|---|
| 59 |
|
|---|
| 60 | i.duration = S * 1000 * rho / Math.SQRT2;
|
|---|
| 61 |
|
|---|
| 62 | return i;
|
|---|
| 63 | }
|
|---|
| 64 |
|
|---|
| 65 | zoom.rho = function(_) {
|
|---|
| 66 | var _1 = Math.max(1e-3, +_), _2 = _1 * _1, _4 = _2 * _2;
|
|---|
| 67 | return zoomRho(_1, _2, _4);
|
|---|
| 68 | };
|
|---|
| 69 |
|
|---|
| 70 | return zoom;
|
|---|
| 71 | })(Math.SQRT2, 2, 4);
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.