# Difference between revisions of "FreeCAD vector math library/de"

Other languages:
čeština • ‎Deutsch • ‎English • ‎español • ‎français • ‎italiano • ‎polski • ‎русский • ‎svenska

Dies ist eine Python-Datei mit einigen nützlichen Funktionen zur Manipulation von Freecad-Vektoren. Füge einfach den folgenden Code in eine Python-Datei ein und importiere diese Datei in dein Python-Skript, um sie zu verwenden. Diese Bibliothek ist im Draft Module enthalten und kann so vom Python-Interpreter aus aufgerufen werden:

```import DraftVecUtils
```

Vectors are the building bricks of almost all 3D geometric operations, so it is useful to know a bit about them to understand how these functions can be useful to you. A couple of good pages to learn the basics of vector math:

``` "Vector math library for FreeCAD"

def sub(first, other):
"sub(Vector,Vector) - subtracts second vector from first one"

def scale(first,scalar):
"scale(Vector,Float) - scales (multiplies) a vector by a factor"

def length(first):
"lengh(Vector) - gives vector length"
return math.sqrt(first.x*first.x + first.y*first.y + first.z*first.z)

def dist(first, other):
"dist(Vector,Vector) - returns the distance between both points/vectors"
return length(sub(first,other))

def normalized(first):
"normalized(Vector) - returns a unit vector"
l=length(first)

def dotproduct(first, other):
"dotproduct(Vector,Vector) - returns the dot product of both vectors"
return (first.x*other.x + first.y*other.y + first.z*other.z)

"crossproduct(Vector,Vector) - returns the cross product of both vectors.
If only one is specified, cross product is made with vertical axis, thus returning its perpendicular in XY plane"