Vec3D Functions¶
API functions that utilize the vec3d class are grouped here. For details of the class, including member functions, see vec3d.
vec3d¶
|
Set all three elements of the vec3d vector |
Set all three coordinates from a vector of three doubles. |
|
|
Set the X coordinate (index 0) of the vec3d |
|
Set the Y coordinate (index 1) of the vec3d |
|
Set the z coordinate (index 2) of the vec3d |
Set this vec3d to another reflected about the YZ plane, negating X. |
|
Set this vec3d to another reflected about the XZ plane, negating Y. |
|
Set this vec3d to another reflected about the XY plane, negating Z. |
|
|
Get the X coordinate (index 0) of the vec3d |
|
Get the Y coordinate (index 1) of the vec3d |
|
Get the Z coordinate (index 2) of the vec3d |
|
Rotate the vec3d about the X axis. |
|
Rotate the vec3d about the Y axis. |
|
Rotate the vec3d about the Z axis. |
|
Scale the X coordinate of the vec3d |
|
Scale the Y coordinate of the vec3d |
|
Scale the Z coordinate of the vec3d |
|
Offset the X coordinate of the vec3d |
|
Offset the Y coordinate of the vec3d |
|
Offset the Z coordinate of the vec3d |
|
Offset one coordinate, chosen by index: 0 for X, 1 for Y, 2 for Z. |
Reflect the vec3d across the XY plane |
|
Reflect the vec3d across the XZ plane |
|
Reflect the vec3d across the YZ plane |
|
Get the magnitude of a vec3d |
|
Get the square of the magnitude. |
|
Normalize the vec3d |
|
Get the index of the largest coordinate: 0 for X, 1 for Y, 2 for Z. |
|
Get the index of the smallest coordinate: 0 for X, 1 for Y, 2 for Z. |
|
Test whether any coordinate is NaN. |
|
Test whether any coordinate is infinite. |
|
Test whether every coordinate is finite -- neither infinite nor NaN. |
- class openvsp.vec3d(*args)[source]¶
vec3d is typically used to describe coordinate points and vectors in 3D space. All 3 elements in the vector are of type double.
- property thisown¶
The membership flag
- property v¶
v : a(3).double
- set_xyz(xx, yy, zz)[source]¶
Set all three elements of the vec3d vector
#==== Test Vec3d ==== a = vec3d() # Default Constructor a.set_xyz( 2.0, 4.0, 6.0 )
- Parameters:
[in] – xx New X value
[in] – yy New Y value
[in] – zz New Z value
- Return type:
- Returns:
Updated vec3d
- set_vec(a)[source]¶
Set all three coordinates from a vector of three doubles.
a = vec3d() a.set_vec( [ 1.0, 2.0, 3.0 ] ) assert abs( a.x() - 1.0 ) < 1e-12, "set_vec did not set x" assert abs( a.z() - 3.0 ) < 1e-12, "set_vec did not set z"
See also: set_xyz :param [in]: a vector<double> Three coordinates, X, Y and Z :rtype:
vec3d:return: vec3d Updated vec3d
- set_x(xx)[source]¶
Set the X coordinate (index 0) of the vec3d
#==== Test Vec3d ==== a = vec3d() # Default Constructor a.set_x( 2.0 )
- Parameters:
[in] – xx New X value
- Return type:
- Returns:
Updated vec3d
- set_y(yy)[source]¶
Set the Y coordinate (index 1) of the vec3d
#==== Test Vec3d ==== a = vec3d() # Default Constructor a.set_y( 4.0 )
- Parameters:
[in] – yy New Y value
- Return type:
- Returns:
Updated vec3d
- set_z(zz)[source]¶
Set the z coordinate (index 2) of the vec3d
#==== Test Vec3d ==== a = vec3d() # Default Constructor a.set_z( 6.0 )
- Parameters:
[in] – zz in double new z value
- Return type:
- Returns:
vec3d result
- set_refx(a)[source]¶
Set this vec3d to another reflected about the YZ plane, negating X.
a = vec3d( 1.0, 2.0, 3.0 ) b = vec3d() b.set_refx( a ) assert abs( b.x() + 1.0 ) < 1e-12, "set_refx did not negate x" assert abs( b.y() - 2.0 ) < 1e-12, "set_refx disturbed y"
See also: set_refy, set_refz, reflect_yz :param [in]: a vec3d Point to reflect :rtype:
vec3d:return: vec3d Updated vec3d
- set_refy(a)[source]¶
Set this vec3d to another reflected about the XZ plane, negating Y.
a = vec3d( 1.0, 2.0, 3.0 ) b = vec3d() b.set_refy( a ) assert abs( b.y() + 2.0 ) < 1e-12, "set_refy did not negate y" assert abs( b.x() - 1.0 ) < 1e-12, "set_refy disturbed x"
See also: set_refx, set_refz, reflect_xz :param [in]: a vec3d Point to reflect :rtype:
vec3d:return: vec3d Updated vec3d
- set_refz(a)[source]¶
Set this vec3d to another reflected about the XY plane, negating Z.
a = vec3d( 1.0, 2.0, 3.0 ) b = vec3d() b.set_refz( a ) assert abs( b.z() + 3.0 ) < 1e-12, "set_refz did not negate z" assert abs( b.x() - 1.0 ) < 1e-12, "set_refz disturbed x"
See also: set_refx, set_refy, reflect_xy :param [in]: a vec3d Point to reflect :rtype:
vec3d:return: vec3d Updated vec3d
- get_pnt(vec3d self, double [3] pnt)[source]¶
- get_pnt(vec3d self, float [3] pnt)
- get_pnt(vec3d self, threed_point_type & pnt)
- x()[source]¶
Get the X coordinate (index 0) of the vec3d
a = vec3d() # Default Constructor a.set_xyz( 2.0, 4.0, 6.0 ) assert abs( a.x() - 2.0 ) < 1e-12, "x did not return the coordinate" assert abs( a[0] - 2.0 ) < 1e-12, "indexing disagrees with x()"
- Return type:
float
- Returns:
X value
- y()[source]¶
Get the Y coordinate (index 1) of the vec3d
a = vec3d() # Default Constructor a.set_xyz( 2.0, 4.0, 6.0 ) assert abs( a.y() - 4.0 ) < 1e-12, "y did not return the coordinate" assert abs( a[1] - 4.0 ) < 1e-12, "indexing disagrees with y()"
- Return type:
float
- Returns:
Y value
- z()[source]¶
Get the Z coordinate (index 2) of the vec3d
a = vec3d() # Default Constructor a.set_xyz( 2.0, 4.0, 6.0 ) assert abs( a.z() - 6.0 ) < 1e-12, "z did not return the coordinate" assert abs( a[2] - 6.0 ) < 1e-12, "indexing disagrees with z()"
- Return type:
float
- Returns:
Z value
- rotate_x(theta)[source]¶
Rotate the vec3d about the X axis.
import math #==== Test Vec3d ==== a = vec3d() # Default Constructor PI = 3.14 a.set_xyz( 1.0, 0.0, 0.0 ) a.rotate_x( 0.5 * PI )
- Parameters:
[in] – theta double Rotation angle in radians
- rotate_y(theta)[source]¶
Rotate the vec3d about the Y axis.
import math #==== Test Vec3d ==== a = vec3d() # Default Constructor PI = 3.14 a.set_xyz( 1.0, 0.0, 0.0 ) a.rotate_y( 0.5 * PI )
- Parameters:
[in] – theta double Rotation angle in radians
- rotate_z(theta)[source]¶
Rotate the vec3d about the Z axis.
import math #==== Test Vec3d ==== a = vec3d() # Default Constructor PI = 3.14 a.set_xyz( 1.0, 0.0, 0.0 ) a.rotate_z( 0.5 * PI )
- Parameters:
[in] – theta double Rotation angle in radians
- scale_x(scale)[source]¶
Scale the X coordinate of the vec3d
#==== Test Vec3d ==== a = vec3d() # Default Constructor #===== Test Scale ==== a.set_xyz( 2.0, 2.0, 2.0 ) a.scale_x( 2.0 )
- Parameters:
[in] – scale Scaling factor for the X value
- scale_y(scale)[source]¶
Scale the Y coordinate of the vec3d
#==== Test Vec3d ==== a = vec3d() # Default Constructor #===== Test Scale ==== a.set_xyz( 2.0, 2.0, 2.0 ) a.scale_y( 2.0 )
- Parameters:
[in] – scale Scaling factor for the Y value
- scale_z(scale)[source]¶
Scale the Z coordinate of the vec3d
#==== Test Vec3d ==== a = vec3d() # Default Constructor #===== Test Scale ==== a.set_xyz( 2.0, 2.0, 2.0 ) a.scale_z( 2.0 )
- Parameters:
[in] – scale Scaling factor for the Z value
- offset_x(offset)[source]¶
Offset the X coordinate of the vec3d
#==== Test Vec3d ==== a = vec3d() # Default Constructor #===== Test Offset ==== a.set_xyz( 2.0, 2.0, 2.0 ) a.offset_x( 10.0 )
- Parameters:
[in] – offset Offset for the X value
- offset_y(offset)[source]¶
Offset the Y coordinate of the vec3d
#==== Test Vec3d ==== a = vec3d() # Default Constructor #===== Test Offset ==== a.set_xyz( 2.0, 2.0, 2.0 ) a.offset_y( 10.0 )
- Parameters:
[in] – offset Offset for the Y value
- offset_z(offset)[source]¶
Offset the Z coordinate of the vec3d
#==== Test Vec3d ==== a = vec3d() # Default Constructor #===== Test Offset ==== a.set_xyz( 2.0, 2.0, 2.0 ) a.offset_z( 10.0 )
- Parameters:
[in] – offset Offset for the Z value
- offset_i(offset, idir)[source]¶
Offset one coordinate, chosen by index: 0 for X, 1 for Y, 2 for Z. The indexed counterpart of offset_x, offset_y and offset_z.
a = vec3d( 1.0, 2.0, 3.0 ) a.offset_i( 0.5, 1 ) assert abs( a.y() - 2.5 ) < 1e-12, "offset_i did not offset the Y coordinate" assert abs( a.x() - 1.0 ) < 1e-12, "offset_i disturbed a coordinate it should not have"
See also: offset_x, offset_y, offset_z :param [in]: offset double Amount to offset by :param [in]: idir int Coordinate index, 0 for X, 1 for Y, 2 for Z
- reflect_xy()[source]¶
Reflect the vec3d across the XY plane
#==== Test Vec3d ==== a = vec3d() # Default Constructor b = vec3d() #===== Test Reflect ==== a.set_xyz( 1.0, 2.0, 3.0 ) b = a.reflect_xy()
- Return type:
- Returns:
Reflected vec3d
- reflect_xz()[source]¶
Reflect the vec3d across the XZ plane
#==== Test Vec3d ==== a = vec3d() # Default Constructor b = vec3d() #===== Test Reflect ==== a.set_xyz( 1.0, 2.0, 3.0 ) b = a.reflect_xz()
- Return type:
- Returns:
Reflected vec3d
- reflect_yz()[source]¶
Reflect the vec3d across the YZ plane
#==== Test Vec3d ==== a = vec3d() # Default Constructor b = vec3d() #===== Test Reflect ==== a.set_xyz( 1.0, 2.0, 3.0 ) b = a.reflect_yz()
- Return type:
- Returns:
Reflected vec3d
- mag()[source]¶
Get the magnitude of a vec3d
import math #==== Test Vec3d ==== a = vec3d() # Default Constructor #==== Test Mag ==== a.set_xyz( 1.0, 2.0, 3.0 ) assert not ( abs( a.mag() - math.sqrt( 14 ) ) > 1e-6 ), "Vec3d Mag"
- Return type:
float
- Returns:
Magnitude
- magsq()[source]¶
Get the square of the magnitude. Cheaper than mag, which has to take a square root, and enough on its own when magnitudes are only being compared.
a = vec3d( 1.0, 2.0, 3.0 ) assert abs( a.magsq() - 14.0 ) < 1e-12, "magsq did not return the squared magnitude"
See also: mag :rtype: float :return: double Squared magnitude
- normalize()[source]¶
Normalize the vec3d
#==== Test Vec3d ==== a = vec3d() # Default Constructor b = vec3d() c = vec3d() #==== Test Cross ==== a.set_xyz( 4.0, 0.0, 0.0 ) b.set_xyz( 0.0, 3.0, 0.0 ) c = cross( a, b ) c.normalize()
- major_comp()[source]¶
Get the index of the largest coordinate: 0 for X, 1 for Y, 2 for Z.
a = vec3d( 1.0, 5.0, 3.0 ) assert a.major_comp() == 1, "major_comp did not find the largest coordinate"
See also: minor_comp :rtype: int :return: int Index of the largest coordinate
- minor_comp()[source]¶
Get the index of the smallest coordinate: 0 for X, 1 for Y, 2 for Z.
a = vec3d( 1.0, 5.0, 3.0 ) assert a.minor_comp() == 0, "minor_comp did not find the smallest coordinate"
See also: major_comp :rtype: int :return: int Index of the smallest coordinate
- isnan()[source]¶
Test whether any coordinate is NaN.
a = vec3d( 1.0, 2.0, 3.0 ) assert not a.isnan(), "isnan reported a NaN in an ordinary point"
See also: isinf, isfinite :rtype: boolean :return: bool True if any coordinate is NaN
- isinf()[source]¶
Test whether any coordinate is infinite.
a = vec3d( 1.0, 2.0, 3.0 ) assert not a.isinf(), "isinf reported an infinity in an ordinary point"
See also: isnan, isfinite :rtype: boolean :return: bool True if any coordinate is infinite
Operators¶
- vec3d.__add__(other)[source]¶
Addition operator for two vec3d objects, performed by the addition of each corresponding component
a = vec3d() # Default Constructor b = vec3d() a.set_xyz( 1.0, 2.0, 3.0 ) b.set_xyz( 4.0, 5.0, 6.0 ) c = a + b print( "a + b = ", False ) print( c )
- vec3d.__sub__(other)[source]¶
Subtraction operator for two vec3d objects, performed by the subtraction of each corresponding component
a = vec3d() # Default Constructor b = vec3d() a.set_xyz( 1.0, 2.0, 3.0 ) b.set_xyz( 4.0, 5.0, 6.0 ) c = a - b print( "a - b = ", False ) print( c )
- vec3d.__mul__(other)[source]¶
Scalar multiplication operator for a vec3d, performed by the multiplication of each vec3d component and the scalar
a = vec3d() # Default Constructor a.set_xyz( 1.0, 2.0, 3.0 ) b = 1.5 c = a * b print( "a * b = ", False ) print( c )
Functions¶
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Format a vec3d as a string, for printing or writing to a file. |
|
|
|
Sum a vector of vec3d using compensated summation, which keeps the rounding error down over a long list. |
Details¶
- openvsp.to_string(v)[source]¶
Format a vec3d as a string, for printing or writing to a file.
a = vec3d( 1.0, 2.0, 3.0 ) s = to_string( a ) assert len( s ) > 0, "to_string returned nothing"
- Parameters:
[in] – v vec3d Point to format
- Return type:
string
- Returns:
string The formatted point
- openvsp.compsum(x)[source]¶
Sum a vector of vec3d using compensated summation, which keeps the rounding error down over a long list.
pts = Vec3dVec( [ vec3d( 1.0, 0.0, 0.0 ), vec3d( 0.0, 2.0, 0.0 ), vec3d( 0.0, 0.0, 3.0 ) ] ) s = compsum( pts ) assert abs( s.x() - 1.0 ) < 1e-12, "compsum is wrong in x" assert abs( s.z() - 3.0 ) < 1e-12, "compsum is wrong in z"
- Parameters:
[in] – x vector<vec3d> Points to sum
- Return type:
- Returns:
vec3d Sum of the points