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

Other languages:
Deutsch • ‎English • ‎Türkçe • ‎español • ‎français • ‎italiano • ‎polski • ‎română • ‎svenska • ‎čeština • ‎русский

## Introduzione

Questo è un modulo Python contenente un paio di funzioni utili per manipolare i vettori. Questa libreria è inclusa in Draft ed è possibile accedervi in questo modo dall'interprete Python:

import DraftVecUtils

Please note that this module was created a long time ago, when the Vector class didn't have many of its methods. Now these operations can be done by the Vector class itself.

Although the DraftVecUtils module still exists, and it is still used inside the Draft Workbench, it is probably better to use the Vector methods directly for new developments.

## Functions

I vettori sono i mattoni costitutivi di quasi tutte le operazioni geometriche 3D, quindi è utile conoscerli un po' per capire come queste funzioni possono essere utili. Ecco alcune valide pagine per imparare le basi della matematica vettoriale:

import math

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"""