MCPcopy Create free account
hub / github.com/plotly/plotly.js / findIntersectionXY

Function findIntersectionXY

src/plots/polar/helpers.js:45–89  ·  view source on GitHub ↗
(v0, v1, a, xpyp)

Source from the content-addressed store, hash-verified

43// given an (xp,yp) pair on the 'v0' <-> 'v1' line
44// (N.B. 'v0' and 'v1' are angles in radians)
45function findIntersectionXY(v0, v1, a, xpyp) {
46 var xstar, ystar;
47
48 var xp = xpyp[0];
49 var yp = xpyp[1];
50 var dsin = clampTiny(Math.sin(v1) - Math.sin(v0));
51 var dcos = clampTiny(Math.cos(v1) - Math.cos(v0));
52 var tanA = Math.tan(a);
53 var cotanA = clampTiny(1 / tanA);
54 var m = dsin / dcos;
55 var b = yp - m * xp;
56
57 if(cotanA) {
58 if(dsin && dcos) {
59 // given
60 // g(x) := v0 -> v1 line = m*x + b
61 // h(x) := ray at angle 'a' = m*x = tanA*x
62 // solve g(xstar) = h(xstar)
63 xstar = b / (tanA - m);
64 ystar = tanA * xstar;
65 } else if(dcos) {
66 // horizontal v0 -> v1
67 xstar = yp * cotanA;
68 ystar = yp;
69 } else {
70 // vertical v0 -> v1
71 xstar = xp;
72 ystar = xp * tanA;
73 }
74 } else {
75 // vertical ray
76 if(dsin && dcos) {
77 xstar = 0;
78 ystar = b;
79 } else if(dcos) {
80 xstar = 0;
81 ystar = yp;
82 } else {
83 // does this case exists?
84 xstar = ystar = NaN;
85 }
86 }
87
88 return [xstar, ystar];
89}
90
91// solves l^2 = (f(x)^2 - yp)^2 + (x - xp)^2
92// rearranged into 0 = a*x^2 + b * x + c

Callers 1

findXYFunction · 0.85

Calls 1

clampTinyFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…