UnitsNet icon indicating copy to clipboard operation
UnitsNet copied to clipboard

Unit Arithmetic

Open rjs5327 opened this issue 2 years ago • 3 comments

Is your feature request related to a problem? Please describe. Allow for there to be math between units to make combined units Torque = Force * Length

Basically adding in the unknown unit classes from the https://github.com/MadsKirkFoged/EngineeringUnits library and adding this function to Units Test

rjs5327 avatar Oct 18 '23 00:10 rjs5327

Also Please Add to the Documentation a example of how to do the math. I found a work around on this. I feel that should be in the about page since the .Kilograms converts it to a double value that then can be used.

    public static MassMomentOfInertia SolidCylinderInertia(Mass mass, Length radius)
    {
        return MassMomentOfInertia.FromKilogramSquareMillimeters( mass.Kilograms * radius.Millimeters * radius.Millimeters / 2.0);
    }

rjs5327 avatar Oct 18 '23 01:10 rjs5327

Also some documentation on Why this is not allowed

    public static Torque TorqueAcc(MassMomentOfInertia InertiaTotal, RotationalAcceleration Rad_Sec2, Torque FrictionTorque)
    {

// Does not Work - Throws a error Torque torque = InertiaTotal* Rad_Sec2; return torque + FrictionTorque; }

But this works and is allowed

    public static MassMomentOfInertia BallScrewInertia(Length Diameter, Length Length, Density density)
    {
        Volume screwVolume =  Volume.FromCubicMillimeters(Math.PI * (Diameter.Millimeters / 2)* (Diameter.Millimeters / 2) * Length.Millimeters);
        Mass mass = density*screwVolume;
        return SolidCylinderInertia(mass, Diameter / 2);
    }

Both ways there is a * used but one is ok and the other is not allowed . I see it as best practice is to not rely on it working but i dont follow why it works and does not work

rjs5327 avatar Oct 18 '23 01:10 rjs5327

Sorry for late reply. This question is not clear to me.

All multiplication and division operator overloads are manually added, so we can add more if something is missing.

For example, see how Length.extra.cs defines arithmetic between different quantities relating to itself:

https://github.com/angularsen/UnitsNet/blob/master/UnitsNet/CustomCode/Quantities/Length.extra.cs#L126-L184

angularsen avatar Feb 18 '24 20:02 angularsen

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 7 days.

github-actions[bot] avatar Jul 08 '24 17:07 github-actions[bot]

This issue was automatically closed due to inactivity.

github-actions[bot] avatar Jul 16 '24 02:07 github-actions[bot]