Use approximate sin/cos for faster interpolation.

This particular approximation is taken from
<http://www.devmaster.net/forums/showthread.php?t=5784> but there may well be
better ones out there.  This seems to work nicely though!
This commit is contained in:
Jason Davies 2011-06-22 18:56:58 +01:00
Родитель 5f41452ed2
Коммит c5450fa62a
1 изменённых файлов: 23 добавлений и 2 удалений

Просмотреть файл

@ -8,16 +8,37 @@ var cluster = d3.layout.cluster()
var bundle = d3.layout.bundle();
// From http://www.devmaster.net/forums/showthread.php?t=5784
function sin(x) {
if (x > Math.PI) x -= 2 * Math.PI;
var B = 4 / Math.PI,
C = -4 / (Math.PI * Math.PI),
y = B * x + C * x * Math.abs(x);
//#ifdef EXTRA_PRECISION
var Q = 0.775,
P = 0.225;
y = P * (y * Math.abs(y) - y) + y; // Q * y + P * y * abs(y)
//#endif
return y;
}
function cos(x) {
return sin(x + Math.PI / 2);
}
var line = d3.svg.line()
.interpolate("basis")
.beta(.85)
.x(function(d) {
var r = d.y, a = (d.x - 90) / 180 * Math.PI;
return r * Math.cos(a);
return r * cos(a);
})
.y(function(d) {
var r = d.y, a = (d.x - 90) / 180 * Math.PI;
return r * Math.sin(a);
return r * sin(a);
});
var vis = d3.select("#chart").append("svg:svg")