我试图用阿基米德螺旋作为轴,用D3.js绘制时间线上的数据。

所以我需要一个Javascript函数来传递它
函数将遍历s*d的螺旋弧,并给出x和y笛卡儿坐标(图中的S点,s=10)。螺旋中心的第一点是0,0。
发布于 2014-12-22 22:24:07
谢谢你的帮助贝尔伍德。我试着绘制你的例子,但当我连续绘制5个点时,它变得有点奇怪(见底部的图像)。
我设法在下面的链接中找到了答案。但看起来你很亲密。
Algorithm to solve the points of a evenly-distributed / even-gaps spiral?
我的最后实现是基于上面的链接。
function archimedeanSpiral(svg,data,circleMax,padding,steps) {
var d = circleMax+padding;
var arcAxis = [];
var angle = 0;
for(var i=0;i<steps;i++){
var radius = Math.sqrt(i+1);
angle += Math.asin(1/radius);//sin(angle) = opposite/hypothenuse => used asin to get angle
var x = Math.cos(angle)*(radius*d);
var y = Math.sin(angle)*(radius*d);
arcAxis.push({"x":x,"y":y})
}
var lineFunction = d3.svg.line()
.x(function(d) { return d.x; })
.y(function(d) { return d.y; })
.interpolate("cardinal");
svg.append("path")
.attr("d", lineFunction(arcAxis))
.attr("stroke", "gray")
.attr("stroke-width", 5)
.attr("fill", "none");
var circles = svg.selectAll("circle")
.data(arcAxis)
.enter()
.append("circle")
.attr("cx", function (d) { return d.x; })
.attr("cy", function (d) { return d.y; })
.attr("r", 10);
return(arcAxis);
}http://s14.postimg.org/90fgp41o1/spiralexample.jpg
发布于 2014-12-22 20:38:30
试一试没什么坏处:(请原谅我的新手javascript)
function spiralPoint(dist, sep, step) {
this.x = 0;
this.y = 0;
var r = dist;
var b = sep / (2 * Math.PI);
var phi = r / b;
for(n = 0; n < step-1; ++n) {
phi += dist / r;
r = b * phi;
}
this.x = r * Math.cos(phi);
this.y = r * Math.sin(phi);
this.print = function() {
console.log(this.x + ', ' + this.y);
};
}
new spiralPoint(1,1,10).print();https://stackoverflow.com/questions/27596115
复制相似问题