Cartesian and polar coordinates library

I need to start working with cartesian and polar points, on a flat surface, nothing geospatial.

I have two beginner’s questions on this field, I prefer asking before rather than being sorry later on…

  • is there a library or wrapper you would recommend?

  • since what I have in mind involves a lot of rotations and translations, and afterward comparing points to be (approximately) equal, is ok to work with Double or a more configurable type like BigDecimal is a safer choice? It is not strictly a matter of precision, Double I think would be ok for that, but more related to the multiple transformations, I fear round-off errors creeping in.

Thank you in advance for your suggestions.

mcallisto,

Spire might be a good fit. Spire: Readme and https://github.com/typelevel/spire . I know they’ve done a lot of work with rational numbers for performance, and should have trigonometry functions.

Another option is to roll-your-own rational number case class with a pair of Ints or Longs. That’d save you from round-off error from Double without the work of BigDecimal, and still perform well. I did that for a bayesian network. I enjoyed be able to reason about fractions being equal; the code was a lot cleaner.

Hope that helps,

David

1 Like

Hello @dwalend thank you for your kind reply.

I am ruling out Spire for the time being since it has not (yet) a Scala3 version.

As for rational case class, that is an interesting tip, I need to better check if it makes sense in my scenario.

For the time being I started building on top of javaGeom which comes with configurable accuracy and a nice almostEquals method. Based on Double. I plan to test step by step if it is enough for my needs.

Mario

Mathematica has a very extensive coordinates library, including several coordinate systems you may not have used or even heard of. It also has several conversion routines, such as FromPolarCoordinates and ToPolarCoordinates. I use Mathematicca to develop and test algorithms extensively. Mathematica could also be used to test implementations of algorithms because it has a nice interface with Java: Just run the algorithm in some other language and then compare the results with the Mathematica implementation. There is almost no limit to the precision you can make Mathematica perform computations.