ekmett / linear

Low-dimensional linear algebra primitives for Haskell.
http://hackage.haskell.org/package/linear
Other
198 stars 50 forks source link

add function (V2 to its angle(inverse of `angle`)) #136

Open suzumiyasmith opened 6 years ago

suzumiyasmith commented 6 years ago

I use this function a lot.

unAngle :: V2 Double -> Double
unAngle (V2 ax ay) =
  let alpha = asin $ ay / (ax * ax + ay * ay)
  in if ax < 0
       then pi - alpha
       else alpha

Shoud we add it to Linear.V2?

ekmett commented 6 years ago

Kicking things around it'd almost be better to present this as a prism or iso, except for the normalization issue. =/

I have no real objection to adding it. I'd probably bikeshed the name to 'unangle' or 'toAngle' though.

phadej commented 6 years ago

Would it make sense to have polar :: Iso' (V2 a) (a, a) ?

ekmett commented 6 years ago

We have such an iso for Data.Complex.

ekmett commented 6 years ago

http://hackage.haskell.org/package/lens-4.15.4/docs/Data-Complex-Lens.html#v:_polar

ekmett commented 6 years ago

I have no particular issue with adding a definition for it here.