angularsen / UnitsNet

Makes life working with units of measurement just a little bit better.
https://www.nuget.org/packages/UnitsNet/
MIT No Attribution
2.19k stars 380 forks source link

Unit Arithmetic #1322

Closed rjs5327 closed 2 months ago

rjs5327 commented 11 months ago

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 commented 11 months ago

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 commented 11 months ago

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

angularsen commented 7 months ago

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

github-actions[bot] commented 3 months ago

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] commented 2 months ago

This issue was automatically closed due to inactivity.