units
units copied to clipboard
Support for equivalent units
The following code calculates the angular acceleration when applying torque to a body with a given rotational inertia. However, the resulting unit [N/(kg*m)] should be convertible to [rad/s^2]. What support is there for this in the library?
using kilogram_meters_squared_t = decltype(1.0_kg * 1.0_sq_m);
using radians_per_second_squared_t = decltype(1.0_rad / 1.0_s / 1.0_s);
const kilogram_meters_squared_t inertia = kilogram_meters_squared_t{1.0};
const newton_meter_t torque = 1.0_Nm;
// Conversion should happen automatically
const radians_per_second_squared_t angular_acc{(torque / inertia).to<float>()};
@simonvpe it seems this lib does not offer inertia types. Maybe instead of using + decltype, you may have to try this inside your code:
namespace units {
UNIT_ADD(inertia,
kilogram_square_meter,
kilogram_square_meters,
kgm2,
compound_unit<mass::kilogram, squared<length::meter>>)
} // namespace units
Same for other types, maybe this can fix your issue.