Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unit Arithmetic #1322

Open
rjs5327 opened this issue Oct 18, 2023 · 3 comments
Open

Unit Arithmetic #1322

rjs5327 opened this issue Oct 18, 2023 · 3 comments

Comments

@rjs5327
Copy link

rjs5327 commented Oct 18, 2023

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
Copy link
Author

rjs5327 commented Oct 18, 2023

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
Copy link
Author

rjs5327 commented Oct 18, 2023

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
Copy link
Owner

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants