Units: Difference between revisions

From FreeCAD Documentation
(Removed Unit_Management_System_Proposal link. Page was deleted.)
 
(85 intermediate revisions by 16 users not shown)
Line 1: Line 1:
<languages/>
{{TOCright}}
<translate>


<!--T:1-->
Here some reading about units:
Some reading about units:
*[http://en.wikipedia.org/wiki/Metrology Metrology]
*[http://en.wikipedia.org/wiki/International_System_of_Units SI system]
*[http://en.wikipedia.org/wiki/International_System_of_Units SI system]
*[http://en.wikipedia.org/wiki/Imperial_units Imperial units]
*[http://en.wikipedia.org/wiki/Imperial_units Imperial units]
*[http://en.wikipedia.org/wiki/SI_derived_unit SI derived units]
*[http://en.wikipedia.org/wiki/SI_derived_unit SI derived units]
*[http://en.wikipedia.org/wiki/Degree_%28angle%29 angle units]
*[http://en.wikipedia.org/wiki/Degree_%28angle%29 angle units]
*[https://github.com/3drepo/occt/blob/master/src/UnitsAPI/Units.dat unit implemented in OCC]


== Examples ==
== Examples == <!--T:2-->


</translate>
# -- some examples of the FreeCAD unit translation system --
{{Code|code=
# make a shorcut for the examples
# -- some examples of the FreeCAD unit translation system --
tu = App.translateUnit
# make a shortcut for the examples
pq = FreeCAD.Units.parseQuantity
# 10 meteres in internel numbers
tu('10 m')
# doing math
tu('3/8 in')
# combined stuff
tu('100 km/h')
# transfer to other units
tu('100 km/h')/tu('m/s')
# derived units (Ohm)
tu('m^-2*kg*s^-3*A^1')
# or
tu('(kg*A)/(m^2*s^3)')


# 10 meters in internal numbers
pq('10 m')


# doing math
== supported units ==
pq('3/8 in')
Here the in FreeCAD defined units so far. Its easy to add one. The definition is here[http://free-cad.svn.sourceforge.net/viewvc/free-cad/trunk/src/Base/UnitsApi.l?view=markup].
"mm" 1.0; // milimeter (internal standard length)
"m" 1000.0; // meter
"cm" 10.0; // centimeter
"dm" 100.0; // decimeter
"km" 1000000.0; // kilometer
"in" 25.4; // inch
"fo" 304.8; // foot
"th" 0.0254; // thou
"yr" 914.4; // yard
"kg" 1.0; // kilogramm (internal standard mass)
"g" 0.001; // gramm
"mg" 0.000001; // miligramm
"t" 1000.0; // ton
"lb" 0.45359237; // pound
"oz" 0.45359237; // ounce
"st" 6.35029318; // Stone
"cwt" 50.80234544;// hundredwights
"deg" 1.0; // degree (internal standard angle)
"rad" 180/M_PI; // radian
"gon" 360.0/400.0;// gon
"s" 1.0; // second (internal standard time)
"min" 60.0; // minute
"h" 3600.0; // hour
"A" 1.0; // second (internal standard electric current)
"K" 1.0; // second (internal standard thermodynamic temperature)
"cd" 1.0; // second (internal standard luminous intensity)
"mol" 1.0; // second (internal standard amount of substance)


# combined stuff
"mL" 1.0; // microliter mm^3 (derived standard volume)
pq('100 km/h')
"L" 1000000.0; // Liter dm^3

# transfer to other units
pq('100 km/h')/tu('m/s')

# derived units (Ohm)
pq('m^2*kg*s^-3*A^-2')

# or
pq('(m^2*kg)/(A^2*s^3)')

# angles
pq('2*pi rad') # full circle

# as gon
pq('2*pi rad') / tu('gon')

# more imperial
tu('1ft (3+7/16)in')

# or
pq('1\' (3+7/16)"') # the ' we have to escape because of python

# trigonometry
pq('sin(pi)')

# Using translated units as parameters, this command will create a 50.8mm x 20mm x 10mm box
b = Part.makeBox(pq('2in'), pq('2m')/100, 10)
}}
<translate>

== Supported units == <!--T:79-->

<!--T:4-->
A complete list of all supported units can be [[Expressions#Units |found here]].

== See Also == <!--T:76-->

<!--T:78-->
* The [[Expressions#Units|Expressions]] page for a list of all known units.
* The documentation of [[Quantity|Quantity]].
* The [[Std_UnitsCalculator|Std UnitsCalculator]] tool.


</translate>
{{Powerdocnavi{{#translation:}}}}

Latest revision as of 14:04, 4 June 2022

Some reading about units:

Examples

# -- some examples of the FreeCAD unit translation system --
# make a shortcut for the examples
pq = FreeCAD.Units.parseQuantity

# 10 meters in internal numbers
pq('10 m')

# doing math
pq('3/8 in')

# combined stuff
pq('100 km/h')

# transfer to other units
pq('100 km/h')/tu('m/s')

# derived units (Ohm)
pq('m^2*kg*s^-3*A^-2')

# or
pq('(m^2*kg)/(A^2*s^3)')

# angles 
pq('2*pi rad') # full circle

# as gon
pq('2*pi rad') / tu('gon')

# more imperial
tu('1ft (3+7/16)in')

# or 
pq('1\' (3+7/16)"') # the ' we have to escape because of python

# trigonometry
pq('sin(pi)')

# Using translated units as parameters, this command will create a 50.8mm x 20mm x 10mm box
b = Part.makeBox(pq('2in'), pq('2m')/100, 10)

Supported units

A complete list of all supported units can be found here.

See Also