Finding x, y coordinates of a point on an Archimedean spiral

I am trying to plot data on a timeline using an Archimedean spiral as an axis using D3.js.

Axis

So I need a Javascript function where I pass it

  • D distance for each step
  • S few steps
  • X distance between each spiral arm

The function will traverse the spiral arc at a distance s * d and give me x and y cartesian coordinates (point S in the diagram, where s = 10). The first point in the center of the spiral is at 0.0.

+3


source to share


2 answers


Thank you for your help. I tried to plot your example, but it is a little strange when I plotted 5 consecutive points (see screenshot below).

I managed to find the answer from the link below. It sounds like you were very close.

Algorithm to solve points of uniformly distributed / even breaks of a spiral?



My final implementation is based on the link above.

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

+2


source


Wouldn't hurt to try: (sorry my javascript newbie)



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();

      

+1


source







All Articles