0
$\begingroup$

I'm learning to code the equation for a logarithmic spiral for a graphics visualization. However, it appears to be inverted with the radius getting smaller (rather than larger) toward the outside of the curve. How can I invert the result so the radius gets larger as the curve moves outward?

var theta = 1; // begin at theta 1
for (var p = 0; p < particleCount; p++) {
    // LOG SPIRAL SHAPE
    var a = 500; // a constant
    var b = 0.2; // another constant
    var pX = a * Math.cos(theta) * Math.log(b * theta);
    var pY = a * Math.sin(theta) * Math.log(b * theta);
    theta += 1; // increment theta
    // place an image at pX,pY and repeat

Since a picture is worth a thousand words (or lines of code), here is the result:

enter image description here

$\endgroup$
2
  • $\begingroup$ Well, where is your problem? Note the outer "particles" are the ones generated last, but the logarithm grows very slowly. This is why the points are more dense at the outside. And you'll probably want to ensure not to have a negative radius, thus $b\theta \ge 1$ is required. $$$$ Also, the logarithmic spiral, as you can see from the article, needs $\cos \theta \cdot \exp(b\cdot\theta)$, not $\cos(\theta)\cdot \log(b\theta)$ $\endgroup$
    – AlexR
    Commented Jul 23, 2014 at 18:46
  • $\begingroup$ Also, if you want your spiral to look better, I suspect you should multiply theta by $\pi/180$ before feeding it to the sin and cos functions. Computer trig functions typically assume that the argument is in radians. $\endgroup$ Commented Jul 23, 2014 at 18:48

1 Answer 1

0
$\begingroup$

Replace Math.log(b * theta) by Math.exp(b * theta) and things should agree with the formulas from the article you referenced.

$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .