我正在尝试使用Archimedean螺旋作为轴并使用D3.js在时间线上绘制数据。
javascript - 在阿基米德螺旋线上找到点的x,y坐标-LMLPHP

所以我需要的是一个Javascript函数

  • 每一步的距离
  • S
  • 的一些步骤
  • X每个螺旋臂之间的距离

  • 该函数将遍历螺旋弧达s * d的距离,并给出x和y直角坐标(在图中s = 10的点S)。螺旋中心的第一个点为0,0。

    最佳答案

    感谢您的所有帮助belwood。我尝试绘制您的示例,但是当我连续绘制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

    09-25 17:10
    查看更多