nholthaus / units

a compile-time, header-only, dimensional analysis and unit conversion library built on c++14 with no dependencies.
http://nholthaus.github.io/units/
MIT License
962 stars 137 forks source link

angular velocity (w= s/r) #104

Closed Papakura closed 6 years ago

Papakura commented 6 years ago

Hi,

I'm attempting to calculate angular velocity where

w (rad/s) = s (meters/s) / r (meters)

but the types are not compatible.

so ended up creating operator overloads for

s (meters/s) / r (meters) - (/ operator)

and

*w (rad/s) r (meters)* - ( operator)

I wanted to check if there was a more optimal way of doing this?

nholthaus commented 6 years ago

You hit an annoying pain point with the library. For better dimensional analysis, the library treats radians as a dimension, but meters/meters winds up as a dimensionless unit. There's no way to really figure that out using only the type system, because the two would have the same type but different meanings. There's also context to consider: not every meter/meter quantity represents a radian.

If possible, the best thing to do is create a radian type from your meter/meter type before hand (using a cast), and then the conversions and dimensional analysis should work as expected. The overloads, for your context, don't seem that bad to me, although probably a bit more difficult to implement.