FreeCAD vector math library/de: Difference between revisions
(Created page with "Vektoren sind die Bausteine fast aller geometrischen 3D-Operationen, daher ist es nützlich, ein wenig über sie zu wissen, um zu verstehen, wie diese Funktionen für Dich nü...") |
No edit summary |
||
(11 intermediate revisions by 3 users not shown) | |||
Line 1: | Line 1: | ||
<languages/> |
<languages/> |
||
⚫ | Dies ist eine Python- |
||
<span id="Introduction"></span> |
|||
⚫ | |||
==Einleitung== |
|||
⚫ | |||
{{Code|code= |
|||
⚫ | |||
}} |
|||
Bitte beachte, dass dieses Modul vor langer Zeit erstellt wurde, als die {{incode|Vector}}-Klasse viele ihrer Methoden noch nicht hatte. Nun können diese Operationen von der Vector-Klasse selbst erledigt werden. |
|||
Obwohl das {{incode|DraftVecUtils}}-Modul weiterhin existiert und es immer noch im [[Draft_Workbench/de|Draft-Arbeitsbereich]] benutzt wird, ist es vermutlich besser, für neue Entwicklungen direkt die {{incode|Vector}}-Methoden zu verwenden. |
|||
<span id="Functions"></span> |
|||
==Funktionen== |
|||
Vektoren sind die Bausteine fast aller geometrischen 3D-Operationen, daher ist es nützlich, ein wenig über sie zu wissen, um zu verstehen, wie diese Funktionen für Dich nützlich sein können. Ein paar gute Seiten, um die Grundlagen der Vektor-Mathematik zu lernen: |
Vektoren sind die Bausteine fast aller geometrischen 3D-Operationen, daher ist es nützlich, ein wenig über sie zu wissen, um zu verstehen, wie diese Funktionen für Dich nützlich sein können. Ein paar gute Seiten, um die Grundlagen der Vektor-Mathematik zu lernen: |
||
* http://en.wikipedia.org/wiki/Vector_space |
* http://en.wikipedia.org/wiki/Vector_space |
||
* http://maths-wiki.wikispaces.com/Vectors |
* http://maths-wiki.wikispaces.com/Vectors |
||
* http://darksleep.com/player/opengl_coordinate_system_and_matrix_math.html |
* http://darksleep.com/player/opengl_coordinate_system_and_matrix_math.html |
||
<pre> |
|||
⚫ | |||
{{Code|code= |
|||
⚫ | |||
⚫ | |||
import math |
|||
⚫ | |||
def add(first, other): |
|||
"""add(Vector,Vector) - adds two vectors""" |
|||
if isinstance(first,FreeCAD.Vector) and isinstance(other,FreeCAD.Vector): |
|||
return FreeCAD.Vector(first.x+other.x, first.y+other.y, first.z+other.z) |
|||
def sub(first, other): |
|||
"""sub(Vector,Vector) - subtracts second vector from first one""" |
|||
if isinstance(first,FreeCAD.Vector) and isinstance(other,FreeCAD.Vector): |
|||
return FreeCAD.Vector(first.x-other.x, first.y-other.y, first.z-other.z) |
|||
def scale(first,scalar): |
|||
"""scale(Vector,Float) - scales (multiplies) a vector by a factor""" |
|||
if isinstance(first,FreeCAD.Vector): |
|||
return FreeCAD.Vector(first.x*scalar, first.y*scalar, first.z*scalar) |
|||
def length(first): |
|||
"""lengh(Vector) - gives vector length""" |
|||
if isinstance(first,FreeCAD.Vector): |
|||
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""" |
|||
if isinstance(first,FreeCAD.Vector) and isinstance(other,FreeCAD.Vector): |
|||
return length(sub(first,other)) |
|||
def normalized(first): |
|||
"""normalized(Vector) - returns a unit vector""" |
|||
if isinstance(first,FreeCAD.Vector): |
|||
l=length(first) |
|||
return FreeCAD.Vector(first.x/l, first.y/l, first.z/l) |
|||
def dotproduct(first, other): |
|||
"""dotproduct(Vector,Vector) - returns the dot product of both vectors""" |
|||
if isinstance(first,FreeCAD.Vector) and isinstance(other,FreeCAD.Vector): |
|||
return (first.x*other.x + first.y*other.y + first.z*other.z) |
|||
def crossproduct(first, other=FreeCAD.Vector(0,0,1)): |
|||
"""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""" |
|||
if isinstance(first,FreeCAD.Vector) and isinstance(other,FreeCAD.Vector): |
|||
return FreeCAD.Vector(first.y*other.z - first.z*other.y, first.z*other.x - first.x*other.z, first.x*other.y - first.y*other.x) |
|||
def angle(first, other=FreeCAD.Vector(1,0,0)): |
|||
"""angle(Vector,Vector) - returns the angle in radians between the two vectors. |
|||
If only one is given, angle is between the vector and the horizontal East direction""" |
|||
if isinstance(first,FreeCAD.Vector) and isinstance(other,FreeCAD.Vector): |
|||
return math.acos(dotproduct(normalized(first),normalized(other))) |
|||
def project(first, other): |
|||
"""project(Vector,Vector): projects the first vector onto the second one""" |
|||
if isinstance(first,FreeCAD.Vector) and isinstance(other,FreeCAD.Vector): |
|||
return scale(other, dotproduct(first,other)/dotproduct(other,other)) |
|||
}} |
|||
</pre> |
|||
[[Category:Poweruser_Documentation]] |
|||
{{Powerdocnavi{{#translation:}}}} |
|||
[[Category:Developer Documentation{{#translation:}}]] |
|||
[[Category:Python Code{{#translation:}}]] |
|||
{{clear}} |
{{clear}} |
Latest revision as of 07:39, 26 November 2023
Einleitung
Dies ist eine Python-Modul mit einigen nützlichen Funktionen zur Manipulation von Vektoren. Diese Bibliothek ist im Draft-Arbeitsbereich enthalten und kann so vom Python-Interpreter aus aufgerufen werden:
import DraftVecUtils
Bitte beachte, dass dieses Modul vor langer Zeit erstellt wurde, als die Vector
-Klasse viele ihrer Methoden noch nicht hatte. Nun können diese Operationen von der Vector-Klasse selbst erledigt werden.
Obwohl das DraftVecUtils
-Modul weiterhin existiert und es immer noch im Draft-Arbeitsbereich benutzt wird, ist es vermutlich besser, für neue Entwicklungen direkt die Vector
-Methoden zu verwenden.
Funktionen
Vektoren sind die Bausteine fast aller geometrischen 3D-Operationen, daher ist es nützlich, ein wenig über sie zu wissen, um zu verstehen, wie diese Funktionen für Dich nützlich sein können. Ein paar gute Seiten, um die Grundlagen der Vektor-Mathematik zu lernen:
- http://en.wikipedia.org/wiki/Vector_space
- http://maths-wiki.wikispaces.com/Vectors
- http://darksleep.com/player/opengl_coordinate_system_and_matrix_math.html
"""Vector math library for FreeCAD"""
import math
import FreeCAD
def add(first, other):
"""add(Vector,Vector) - adds two vectors"""
if isinstance(first,FreeCAD.Vector) and isinstance(other,FreeCAD.Vector):
return FreeCAD.Vector(first.x+other.x, first.y+other.y, first.z+other.z)
def sub(first, other):
"""sub(Vector,Vector) - subtracts second vector from first one"""
if isinstance(first,FreeCAD.Vector) and isinstance(other,FreeCAD.Vector):
return FreeCAD.Vector(first.x-other.x, first.y-other.y, first.z-other.z)
def scale(first,scalar):
"""scale(Vector,Float) - scales (multiplies) a vector by a factor"""
if isinstance(first,FreeCAD.Vector):
return FreeCAD.Vector(first.x*scalar, first.y*scalar, first.z*scalar)
def length(first):
"""lengh(Vector) - gives vector length"""
if isinstance(first,FreeCAD.Vector):
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"""
if isinstance(first,FreeCAD.Vector) and isinstance(other,FreeCAD.Vector):
return length(sub(first,other))
def normalized(first):
"""normalized(Vector) - returns a unit vector"""
if isinstance(first,FreeCAD.Vector):
l=length(first)
return FreeCAD.Vector(first.x/l, first.y/l, first.z/l)
def dotproduct(first, other):
"""dotproduct(Vector,Vector) - returns the dot product of both vectors"""
if isinstance(first,FreeCAD.Vector) and isinstance(other,FreeCAD.Vector):
return (first.x*other.x + first.y*other.y + first.z*other.z)
def crossproduct(first, other=FreeCAD.Vector(0,0,1)):
"""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"""
if isinstance(first,FreeCAD.Vector) and isinstance(other,FreeCAD.Vector):
return FreeCAD.Vector(first.y*other.z - first.z*other.y, first.z*other.x - first.x*other.z, first.x*other.y - first.y*other.x)
def angle(first, other=FreeCAD.Vector(1,0,0)):
"""angle(Vector,Vector) - returns the angle in radians between the two vectors.
If only one is given, angle is between the vector and the horizontal East direction"""
if isinstance(first,FreeCAD.Vector) and isinstance(other,FreeCAD.Vector):
return math.acos(dotproduct(normalized(first),normalized(other)))
def project(first, other):
"""project(Vector,Vector): projects the first vector onto the second one"""
if isinstance(first,FreeCAD.Vector) and isinstance(other,FreeCAD.Vector):
return scale(other, dotproduct(first,other)/dotproduct(other,other))
- FreeCAD scripting: Python, Introduction to Python, Python scripting tutorial, FreeCAD Scripting Basics
- Modules: Builtin modules, Units, Quantity
- Workbenches: Workbench creation, Gui Commands, Commands, Installing more workbenches
- Meshes and Parts: Mesh Scripting, Topological data scripting, Mesh to Part, PythonOCC
- Parametric objects: Scripted objects, Viewproviders (Custom icon in tree view)
- Scenegraph: Coin (Inventor) scenegraph, Pivy
- Graphical interface: Interface creation, Interface creation completely in Python (1, 2, 3, 4, 5), PySide, PySide examples beginner, intermediate, advanced
- Macros: Macros, How to install macros
- Embedding: Embedding FreeCAD, Embedding FreeCADGui
- Other: Expressions, Code snippets, Line drawing function, FreeCAD vector math library (deprecated)
- Hubs: User hub, Power users hub, Developer hub