Vector API: Difference between revisions

From FreeCAD Documentation
mNo edit summary
No edit summary
 
(22 intermediate revisions by 7 users not shown)
Line 1: Line 1:
<languages/>
<translate>

<!--T:1-->
{{VeryImportantMessage|(October 2019) Do not edit this page. The information is incomplete and outdated. For the latest API, see the [https://www.freecadweb.org/api autogenerated API documentation], or generate the documentation yourself, see [[Source documentation|Source documentation]].}}

<!--T:20-->
Vectors are used everywhere in FreeCAD.
Vectors are used everywhere in FreeCAD.


<!--T:2-->
Example:
Example:
</translate>
v=FreeCAD.Vector()
{{Code|code=
v=FreeCAD.Vector(1,0,0)
v=FreeCAD.Base.Vector()
v=FreeCAD.Vector()
v2 = FreeCAD.Vector(3,2,-5)
v=FreeCAD.Vector(1,0,0)
v=FreeCAD.Base.Vector()
v3 = v.add(v2)
v2 = FreeCAD.Vector(3,2,-5)
print v3.Length
v3 = v.add(v2)
print v3.Length
}}
<translate>


<!--T:3-->
{{APIProperty|Length|returns the length of the vector.}}
{{APIProperty|Length|returns the length of the vector.}}
{{APIFunction|add|Vector|adds another vector to this one.|vector}}

{{APIFunction|add|Vector|adds another vector to this one|the sum of both vectors.}}
{{APIFunction|cross|Vector|the crossproduct between this vector and another.|vector}}
{{APIFunction|distanceToLine|Vector1,Vector2|the distance between the vector and a line through Vector1 in direction Vector2.|float}}

{{APIFunction|cross|Vector| |the crossproduct between two vectors.}}
{{APIFunction|distanceToPoint|Vector|the distance between this vector and another.|float}}
{{APIFunction|distanceToLineSegment|Vector1,Vector2|a vector to the closest point on a line segment from Vector1 to Vector2.|Vector}}

{{APIFunction|distanceToLine|Vector1,Vector2| |the distance between the vector and a line between Vector1 and Vector2.}}
{{APIFunction|distanceToPlane|Vector1,Vector2|the distance between the vector and a plane defined by a point and a normal.|float}}
{{APIFunction|dot|Vector|the dot product between 2 vectors.|float}}

{{APIFunction|distanceToPlane|Vector1,Vector2| |the distance between the vector and a plane defined by a point and a normal.}}
{{APIFunction|getAngle|Vector|the angle in radians between this vector and another.|float}}
{{APIFunction|isEqual|Vector2,tolerance|Checks if the distance between the points represented by this Vector and Vector2 is less than or equal to the given tolerance.|True/False}}

{{APIFunction|isNormal|Vector2,tolerance|Checks if this Vector is normal to Vector2 within the tolerance.|True/False}}
{{APIFunction|dot|Vector| |the dot product between 2 vectors.}}
{{APIFunction|isOnLineSegment|Vector1,Vector2|Checks if this vector is on the line segment generated by Vector1 and Vector2.|Vector}}

{{APIFunction|isParallel|Vector2,tolerance|Checks if this Vector is parallel to Vector2 within the tolerance.|True/False}}
{{APIFunction|getAngle|Vector| |the angle in radians between 2 vectors.}}
{{APIFunction|multiply|Float|multiplies (uniform scale) a vector by the given factor.|nothing}}

{{APIFunction|multiply|Float|multiplies (scales) a vector by the given factor|nothing.}}
{{APIFunction|negative|Vector|Returns the negative (opposite) of this vector.|Vector}}
{{APIFunction|normalize| |normalizes a vector (sets its length to 1.0).|nothing}}

{{APIFunction|normalize| |normalizes a vector (sets its length to 1.0).|nothing.}}
{{APIFunction|projectToLine|Vector1,Vector2|projects the vector on a line through Vector1 in direction Vector2.|nothing}}
{{APIFunction|projectToPlane|Vector1,Vector2|projects the vector on a plane defined by a point (Vector1) and a normal (Vector2).|nothing}}

{{APIFunction|projectToLine|Vector1,Vector2|projects the vector on a line between Vector1 and Vector2.|nothing.}}
{{APIFunction|scale|Float,Float,Float|Same as multiply but lets specify different values for x, y and z directions. (non-uniform scale)|nothing}}
{{APIFunction|sub|Vector|subtracts another vector from this one.|vector}}

{{APIFunction|projectToPlane|Vector1,Vector2|projects the vector on a plane defined by a point and a normal.|nothing.}}

{{APIFunction|scale|Float,Float,Float|Same as multiply but lets specify different values for x, y and z directions.|nothing.}}

{{APIFunction|sub|Vector|subtracts another vector from the first one.|the resulting vector.}}

{{APIProperty|x|the x coordinate of a vector.}}
{{APIProperty|x|the x coordinate of a vector.}}

{{APIProperty|y|the y coordinate of a vector.}}
{{APIProperty|y|the y coordinate of a vector.}}

{{APIProperty|z|the z coordinate of a vector.}}
{{APIProperty|z|the z coordinate of a vector.}}


</translate>
{{languages | {{es|Vector_API/es}} }}
{{Userdocnavi{{#translation:}}}}

[[Category:API]]
[[Category:API{{#translation:}}]]
[[Category:Poweruser Documentation{{#translation:}}]]
{{clear}}

Latest revision as of 13:51, 15 January 2024

(October 2019) Do not edit this page. The information is incomplete and outdated. For the latest API, see the autogenerated API documentation, or generate the documentation yourself, see Source documentation.

Vectors are used everywhere in FreeCAD.

Example:

v=FreeCAD.Vector()
v=FreeCAD.Vector(1,0,0)
v=FreeCAD.Base.Vector()
v2 = FreeCAD.Vector(3,2,-5)
v3 = v.add(v2)
print v3.Length
Length

Returns: returns the length of the vector.

add(Vector)

Description: adds another vector to this one.

Returns: vector

cross(Vector)

Description: the crossproduct between this vector and another.

Returns: vector

distanceToLine(Vector1,Vector2)

Description: the distance between the vector and a line through Vector1 in direction Vector2.

Returns: float

distanceToPoint(Vector)

Description: the distance between this vector and another.

Returns: float

distanceToLineSegment(Vector1,Vector2)

Description: a vector to the closest point on a line segment from Vector1 to Vector2.

Returns: Vector

distanceToPlane(Vector1,Vector2)

Description: the distance between the vector and a plane defined by a point and a normal.

Returns: float

dot(Vector)

Description: the dot product between 2 vectors.

Returns: float

getAngle(Vector)

Description: the angle in radians between this vector and another.

Returns: float

isEqual(Vector2,tolerance)

Description: Checks if the distance between the points represented by this Vector and Vector2 is less than or equal to the given tolerance.

Returns: True/False

isNormal(Vector2,tolerance)

Description: Checks if this Vector is normal to Vector2 within the tolerance.

Returns: True/False

isOnLineSegment(Vector1,Vector2)

Description: Checks if this vector is on the line segment generated by Vector1 and Vector2.

Returns: Vector

isParallel(Vector2,tolerance)

Description: Checks if this Vector is parallel to Vector2 within the tolerance.

Returns: True/False

multiply(Float)

Description: multiplies (uniform scale) a vector by the given factor.

Returns: nothing

negative(Vector)

Description: Returns the negative (opposite) of this vector.

Returns: Vector

normalize( )

Description: normalizes a vector (sets its length to 1.0).

Returns: nothing

projectToLine(Vector1,Vector2)

Description: projects the vector on a line through Vector1 in direction Vector2.

Returns: nothing

projectToPlane(Vector1,Vector2)

Description: projects the vector on a plane defined by a point (Vector1) and a normal (Vector2).

Returns: nothing

scale(Float,Float,Float)

Description: Same as multiply but lets specify different values for x, y and z directions. (non-uniform scale)

Returns: nothing

sub(Vector)

Description: subtracts another vector from this one.

Returns: vector

x

Returns: the x coordinate of a vector.

y

Returns: the y coordinate of a vector.

z

Returns: the z coordinate of a vector.