Vec3D Functions

API functions that utilize the vec3d class are grouped here. For details of the class, including member functions, see vec3d.

vec3d

vec3d.set_xyz(xx, yy, zz)

Set all three elements of the vec3d vector

vec3d.set_vec(a)

Set all three coordinates from a vector of three doubles.

vec3d.set_x(xx)

Set the X coordinate (index 0) of the vec3d

vec3d.set_y(yy)

Set the Y coordinate (index 1) of the vec3d

vec3d.set_z(zz)

Set the z coordinate (index 2) of the vec3d

vec3d.set_refx(a)

Set this vec3d to another reflected about the YZ plane, negating X.

vec3d.set_refy(a)

Set this vec3d to another reflected about the XZ plane, negating Y.

vec3d.set_refz(a)

Set this vec3d to another reflected about the XY plane, negating Z.

vec3d.x()

Get the X coordinate (index 0) of the vec3d

vec3d.y()

Get the Y coordinate (index 1) of the vec3d

vec3d.z()

Get the Z coordinate (index 2) of the vec3d

vec3d.rotate_x(theta)

Rotate the vec3d about the X axis.

vec3d.rotate_y(theta)

Rotate the vec3d about the Y axis.

vec3d.rotate_z(theta)

Rotate the vec3d about the Z axis.

vec3d.scale_x(scale)

Scale the X coordinate of the vec3d

vec3d.scale_y(scale)

Scale the Y coordinate of the vec3d

vec3d.scale_z(scale)

Scale the Z coordinate of the vec3d

vec3d.offset_x(offset)

Offset the X coordinate of the vec3d

vec3d.offset_y(offset)

Offset the Y coordinate of the vec3d

vec3d.offset_z(offset)

Offset the Z coordinate of the vec3d

vec3d.offset_i(offset, idir)

Offset one coordinate, chosen by index: 0 for X, 1 for Y, 2 for Z.

vec3d.reflect_xy()

Reflect the vec3d across the XY plane

vec3d.reflect_xz()

Reflect the vec3d across the XZ plane

vec3d.reflect_yz()

Reflect the vec3d across the YZ plane

vec3d.mag()

Get the magnitude of a vec3d

vec3d.magsq()

Get the square of the magnitude.

vec3d.normalize()

Normalize the vec3d

vec3d.major_comp()

Get the index of the largest coordinate: 0 for X, 1 for Y, 2 for Z.

vec3d.minor_comp()

Get the index of the smallest coordinate: 0 for X, 1 for Y, 2 for Z.

vec3d.isnan()

Test whether any coordinate is NaN.

vec3d.isinf()

Test whether any coordinate is infinite.

vec3d.isfinite()

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

as_vec2d_xy(vec3d self) → vec2d[source]
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:

vec3d

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_arr(vec3d self, double const [] a) → vec3d[source]
set_arr(vec3d self, float const [] a) → 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:

vec3d

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:

vec3d

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:

vec3d

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

data(vec3d self) → double *[source]
Transform(vec3d self, Matrix4d m)[source]
FlipNormal(vec3d self)[source]
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:

vec3d

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:

vec3d

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:

vec3d

Returns:

Reflected vec3d

swap_xy(vec3d self) → vec3d[source]
swap_xz(vec3d self) → vec3d[source]
swap_yz(vec3d self) → vec3d[source]
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

isfinite()[source]

Test whether every coordinate is finite – neither infinite nor NaN.

a = vec3d( 1.0, 2.0, 3.0 )

assert a.isfinite(), "isfinite rejected an ordinary point"

See also: isnan, isinf :rtype: boolean :return: bool True if all three coordinates are finite

as_numpy()[source]
__rmul__(vec3d self, double b) → vec3d[source]
__neg__(vec3d self) → vec3d[source]
__len__(vec3d self) → int[source]
__setitem__(i, val)[source]
__repr__(vec3d self) → std::string[source]

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 )
vec3d.__truediv__(other)[source]

Scalar division operator for a vec3d, performed by the division of of each vec3d component by 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 )
vec3d.__getitem__(other)[source]

Functions

dist(-> double)

dist_squared(-> double)

dot(-> double)

cross(-> vec3d)

angle(-> double)

signed_angle(vec3d a, vec3d b, vec3d ref)

cos_angle(-> double)

RotateArbAxis(vec3d p, double theta, vec3d r)

to_string(v)

Format a vec3d as a string, for printing or writing to a file.

FitPlane(Vec3dVec pts, vec3d cen, vec3d norm)

compsum(x)

Sum a vector of vec3d using compensated summation, which keeps the rounding error down over a long list.

Details

openvsp.signed_angle(vec3d a, vec3d b, vec3d ref) → double[source]
openvsp.RotateArbAxis(vec3d p, double theta, vec3d r) → vec3d[source]
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.FitPlane(Vec3dVec pts, vec3d cen, vec3d norm)[source]
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:

vec3d

Returns:

vec3d Sum of the points