PhpUnitsOfMeasure / php-units-of-measure

A library for handling physical quantities and the units of measure in which they're represented.
MIT License
305 stars 77 forks source link

Add support for derived physical quantities #27

Open triplepoint opened 10 years ago

triplepoint commented 10 years ago

Here, derived physical quantities are quantities that are defined in terms of other quantities. For example: Velocity = Length / Time Area = Length * Length Acceleration = Length / Time / Time

Currently, derived quantities are treated no differently from "fundamental" quantities, meaning that there's a lot of duplicated effort when managing conversion factors. In addition, there's an opportunity for gaining new units when the fundamental quantity units are extended. For example, if we added "cubit" to the set of units for Length, we could automatically get Cubits/s^2 as a unit for Acceleration.

Figure out how to cleanly represent this relationship between quantities and implement it.

nclavaud commented 3 years ago

Just stumbled upon this while looking for a decent way to model and manipulate derived physical quantities.

I have just read this paper where derived quantities are modelled by a simple array of exponents, something like:

// velocity (m/s)
['length' => 1, 'time' => -1]

// area (m²)
['length' => 2, 'time' => 0]

// acceleration (m/s²)
['length' => 1, 'time' => -2]

With this kind of representation, multiplying/dividing two quantities is just a matter of adding/subtracting the values, key by key:

// area * length = volume
[
    'length' => 3, // 2 + 1
    'time' => 0,   // 0 + 0
]

// length / velocity = time
[
    'length' => 0, // 1 - 1
    'time' => 1,   // 0 - (-1)
]

Not sure it would help, that's just my 2 cents :shrug: