I’d like to calculate x and y coordinates along an equiangular spiral between two known points in javascript.
I’m attempting to convert convert the Julia code found here to javascript:
Drawing an equiangular spiral between two known points in Julia
I’m stuck on this term: exp.(-t)
The natural logarithm of a negative number is undefined, and t should be a positive number.
The other terms appear to be straightforward, but maybe there are other mistakes.
This is what I’ve got, so far:
function hypC(a, b) {
return Math.sqrt(a * a + b * b);
}
let p1 = [1000,1000]
, p2 = [0,0]
, r = hypC(p2[0]-p1[0],p2[1]-p1[1])
, theta_offset = Math.atan((p1[1]-p2[1])/(p1[0]-p2[0]))
//# Number of points
, rez = 1500
//# Number of revolutions
, rev = 5
//# Radius as spiral decreases
, t = 0
, tRange = r
//# Angle as spiral decreases
, theta = 0 + theta_offset
, thetaRange = 2*(Math.PI)*rev
, x , y
;
spiral()
function spiral(){
for (let i=1; i<rez + 1; i++) {
t = tRange * (i/rez)
, theta = thetaRange * (i/rez)
, x = Math.cos(theta) * r * Math.log(-t) + p2[0]
, y = Math.sin(theta) * r * Math.log(-t) + p2[1]
console.log(x,y)
}
}