rough icon indicating copy to clipboard operation
rough copied to clipboard

`atan` versus `atan2`

Open SheetJSDev opened this issue 5 years ago • 2 comments

Both dashed and zigzag use Math.atan:

      const alpha = Math.atan((p2[1] - p1[1]) / (p2[0] - p1[0]));

It would seem that a generated vertical line would cause errors. Is there a reason for preferring this over the safer atan2 alternative?

      const alpha = Math.atan2((p2[1] - p1[1]), (p2[0] - p1[0]));

SheetJSDev avatar May 29 '20 01:05 SheetJSDev

You're correct atan2 would be the better option here, because I don't check for the denominator to be nonzero.

pshihn avatar May 29 '20 01:05 pshihn

I think I have been getting away with it because it is unlikely in zigzag lines, and the randomness in the dashed lines.

pshihn avatar May 29 '20 01:05 pshihn