Skip to main content
Version: 12.0.0

viktor.geometry

VisualisationError

exception viktor.geometry.VisualisationError

Bases: Exception

Vector

class viktor.geometry.Vector(x, y, z=0)

A 3-dimensional vector in space.

The following operations are supported:

  • Negation

    v1 = Vector(1, 2, 3)
    v2 = -v1  # results in Vector(-1, -2, -3)
    
  • Addition

    v1 = Vector(1, 2, 3)
    v2 = Vector(1, 2, 3)
    v3 = v1 + v2  # results in Vector(2, 4, 6)
    
  • Subtraction

    v1 = Vector(1, 2, 3)
    v2 = Vector(1, 2, 3)
    v3 = v1 - v2  # results in Vector(0, 0, 0)
    
  • (reverse) Multiplication

    v1 = Vector(1, 2, 3)
    v2 = v1 * 3  # results in Vector(3, 6, 9)
    v3 = 3 * v1  # results in Vector(3, 6, 9)
    
  • Dot product

    v1 = Vector(1, 2, 3)
    v2 = Vector(1, 2, 3)
    res = v1.dot(v2)  # results in 14
    
  • Cross product

    v1 = Vector(1, 0, 0)
    v2 = Vector(0, 1, 0)
    v3 = v1.cross(v2)  # results in Vector(0, 0, 1)
    
Parameters
  • x (float) – X-coordinate.

  • y (float) – Y-coordinate.

  • z (float) – Z-coordinate (default: 0).

property squared_magnitude

Vector magnitude without square root; faster than magnitude.

Return type

float

property magnitude

Magnitude of the Vector.

Return type

float

property coordinates

Coordinates of the Vector as tuple (X, Y, Z).

Return type

Tuple[float, float, float]

normalize()

Return the normalized vector (with unit-length).

Raises

ValueError – if vector is a null-vector.

Return type

Vector

dot(other)

Scalar product of two vectors.

Parameters

other (Vector) – Second Vector

Return type

float

cross(other)

Vector product of two vectors.

Parameters

other (Vector) – Second Vector

Return type

Vector

Material

class viktor.geometry.Material(name, density=None, price=None, *, threejs_type='MeshStandardMaterial', threejs_roughness=0.7, threejs_metalness=0.8, threejs_opacity=1.0, color=Color(221, 221, 221))
Parameters
  • name (str) –

  • density (Optional[float]) –

  • price (Optional[float]) –

  • color (Color) –

  • threejs_type (str) –

  • threejs_roughness (float) – Between 0 - 1 where closer to 1 gives the material a rough texture.

  • threejs_metalness (float) – Between 0 - 1 where closer to 1 gives the material a shiny metal look.

  • threejs_opacity (float) – Between 0 - 1 where closer to 0 makes the material less visible.

property name
Return type

str

property density
Return type

Optional[float]

property price
Return type

Optional[float]

export_threejs()
Return type

dict

TransformableObject

class viktor.geometry.TransformableObject

Bases: abc.ABC

abstract property threejs_geometries
Return type

List

translate(translation_vector)
rotate(angle, direction, point=None)

Rotate an object along an axis (direction) by an angle. Direction will follow right hand rule

Parameters
  • angle (Union[int, float]) – Angle of desired rotation in radians.

  • direction (List[Union[float, int]]) – Vector along which rotation is to be performed.

  • point (Optional[List[float]]) –

mirror(point, normal)

Return matrix to mirror at plane defined by point and normal vector.

Parameters
  • point (Point) – Point within the mirror plane.

  • normal (List[float]) – Normal vector of the mirror plane.

scale(scaling_vector)

Threejs

class viktor.geometry.Threejs(group)
standard_material_uuid = UUID('d0222bb8-d29b-11eb-b3cb-c8d3ffed610d')
static metadata()
static main_structure()
static standard_material()
static geometry_object(_uuid, name, matrix, geometry_uuid, material_uuid)
static group_object(_uuid, matrix)
static geometry_from_triangle_vertices_faces(_uuid, vertices, faces)
Parameters
  • _uuid (UUID) –

  • vertices (List[List[float]]) – list with unique points, three coordinates grouped in list

  • faces (List[List[int]]) – face has 3 indices. the index matches a specific point in the vertices list. the direction of the surface is determined with a right hand rule on the circumference (ccw in x,y-plane lead to positive z face)

e.g single triangle: >>> vertices = [[0.0, 0.0, 0.0], [1.0, 0.0, 0.0], [1.0, 1.0, 0.0]] >>> faces = [[0, 1, 2]]

e.g single square, consisting of two triangles: >>> vertices = [[0.0, 0.0, 0.0], [0.0, 1.0, 0.0], [1.0, 1.0, 0.0], [1.0, 0.0, 0.0]] >>> faces = [[0, 1, 2], [2, 3, 0]]

export()

Group

class viktor.geometry.Group(objects)

Bases: viktor.geometry.TransformableObject

Parameters

objects (List[TransformableObject]) – Objects that are part of the group.

add(objects)
property children
Return type

List[TransformableObject]

property threejs_geometries
property threejs_object_structure
property threejs_materials
export_visualisation(visualisation='threejs')
duplicate()

Point

class viktor.geometry.Point(x, y, z=0)

This class represents a point object, which is instantiated by means of 3-dimensional coordinates X, Y, and Z. It forms a basis of many structural 2D and 3D objects.

Example usage:

p1 = Point(0, 0)  # creates a point in the origin
p2 = Point(1, 2, 3)
p3 = p2.copy()
Parameters
  • x (float) – X-coordinate.

  • y (float) – Y-coordinate.

  • z (float) – (optional) Z-coordinate, defaults to 0.

Raises

TypeError – if the point is instantiated with a None value.

property coordinates

Coordinates of the Point as array (X, Y, Z).

property x

Returns the X-coordinate.

Return type

float

property y

Returns the Y-coordinate.

Return type

float

property z

Returns the Z-coordinate.

Return type

float

copy()

Returns a deep copy of the object.

Return type

Point

coincides_with(other)

Given another Point object, this method determines whether the two points coincide.

Return type

bool

vector_to(point)

Vector pointing from self to point.

Return type

Vector

get_local_coordinates(local_origin, spherical=False)

Method to determine the local coordinates of the current Point with respect to a ‘local origin’.

Return type

ndarray

Line

class viktor.geometry.Line(start_point, end_point)
Parameters
property start_point
Return type

Point

property end_point
Return type

Point

property length
Return type

float

direction(normalize=True)

Direction vector between start and end point.

Return type

Vector

collinear(point)

True if point is collinear (in line) with Line, else False.

Return type

bool

property length_vector
property unit_vector
property geometries
property horizontal
Return type

bool

property vertical
Return type

bool

discretize(num=2)
revolve(*, material=None, **kwargs)

Revolve line around y-axis, only possible for lines in x-y plane.

Parameters

material (Optional[Material]) – optional material

Raises

NotImplementedError – when line is not in x-y plane

Return type

LineRevolve

get_line_function_parameters()

Get parameters for y=ax+b definition of a line

Return type

Tuple[float, float]

Returns

(a,b) (or nan if line is vertical)

find_overlap(other, inclusive=False)

Find the overlapping part of this line with another line.

The returned value depends on the situation:

  • None, if no overlap is found or the two lines are not parallel

  • Point, if an overlap is found with length equal to 0

  • Line, if an overlap is found with length larger than 0

Parameters
  • other (Line) – Other Line object

  • inclusive – True to treat overlapping points as overlap

Return type

Union[Point, Line, None]

calculate_intersection_bounded_line_with_y

viktor.geometry.calculate_intersection_bounded_line_with_y(line, y_intersection)

Calculate x intersection between two points and y value. Return None if no intersection is found.

Returns x:                              Returns None:

        o
       /
y-----/---                              y---------
     /:                                      o
    / :                                     /
   o  x                                    o
Parameters
  • line (Line) – Line object.

  • y_intersection (float) – y-value of the intersection line.

Return type

Optional[float]

calculate_intersection_extended_line_with_y

viktor.geometry.calculate_intersection_extended_line_with_y(line, y_intersection)

Calculates the intersection x value of a line at a given y value.

Returns x:                              Returns x:

        o
       /
y-----/---                              y----------
     /:                                      o:
    / :                                     / :
   o  x                                    o  x
Parameters
  • line (Line) – Line object.

  • y_intersection (float) – y-value of the intersection line.

Return type

float

line_is_horizontal

viktor.geometry.line_is_horizontal(line)

Returns True if line is horizontal.

Return type

bool

line_is_vertical

viktor.geometry.line_is_vertical(line)

Returns True if line is vertical.

Return type

bool

x_between_bounds

viktor.geometry.x_between_bounds(x, x1, x2, inclusive=True)

Method checks whether the x value is between the bounds x1 and x2.

Parameters
  • x (float) – x-value to be evaluated.

  • x1 (float) – Lower bound.

  • x2 (float) – Upper bound.

  • inclusive (bool) – If set to True, this method will also return True when the x value is equal to either x1 or x2.

Return type

bool

y_between_bounds

viktor.geometry.y_between_bounds(y, y1, y2, inclusive=True)

Method checks whether the y value is between the bounds y1 and y2.

Parameters
  • y (float) – y-value to be evaluated.

  • y1 (float) – Lower bound.

  • y2 (float) – Upper bound.

  • inclusive (bool) – If set to True, this method will also return True when the y value is equal to either y1 or y2.

Return type

bool

point_is_on_bounded_line

viktor.geometry.point_is_on_bounded_line(point, line, inclusive=True)

Method checks whether a given Point object is within the ends of a Line.

Parameters
  • point (Point) – Point to be evaluated.

  • line (Line) – Line object.

  • inclusive (bool) – If set to True, this method will also return True when the point is located on one of the line ends.

Return type

bool

calculate_intersection_extended_line_with_x

viktor.geometry.calculate_intersection_extended_line_with_x(line, x)

Returns the point at which a given line intersects a vertical axis at position x.

Returns P(x, y):                        Returns P(x, y):

        o
       /
y-----P---                              y-----P----
     /:                                      o:
    / :                                     / :
   o  x                                    o  x
Parameters
  • line (Line) – Line to be evaluated.

  • x (float) – x-value of the intersection line.

Return type

Point

get_line_function_parameters

viktor.geometry.get_line_function_parameters(line)

Returns the line function parameters (a, b) of a line (y = ax + b).

Return type

Tuple[float, float]

calculate_intersection_extended_lines

viktor.geometry.calculate_intersection_extended_lines(extended_line1, extended_line2)

Calculate intersection between two lines defined by start/end points. The lines are assumed to extend infinitely: bounds are not taken account. Returns None if lines are parallel (i.e. no intersection exists).

Returns P(x, y):                        Returns P(x, y):                        Returns None:

        o
       /
o-----P---o                             o--o P                                  o-----o
     /                                      o
    /                                      /                                    o--o
   o                                      o
Parameters
  • extended_line1 (Line) – First Line object.

  • extended_line2 (Line) – Second Line object.

Return type

Optional[Point]

calculate_intersection_bounded_line_extended_line

viktor.geometry.calculate_intersection_bounded_line_extended_line(bounded_line, extended_line, inclusive=True)

Calculate intersection between line with fixed endpoints and line which is indefinitely extended.

Parameters
  • bounded_line (Line) – Bounded Line object.

  • extended_line (Line) – Extended Line object.

  • inclusive (bool) – If set to True, this method will also check for end points that are located on one of the line ends.

Return type

Optional[Point]

calculate_intersection_bounded_lines

viktor.geometry.calculate_intersection_bounded_lines(bounded_line1, bounded_line2, inclusive=True)

Calculate intersection between two lines with fixed endpoints.

Parameters
  • bounded_line1 (Line) – First bounded Line object.

  • bounded_line2 (Line) – Second bounded Line object.

  • inclusive (bool) – If set to True, intersections on the endpoint will also be taken into account.

Return type

Optional[Point]

Revolve

class viktor.geometry.Revolve(*args, material=None, **kwargs)

Bases: viktor.geometry.TransformableObject, abc.ABC

Abstract base class of a revolved object.

abstract property surface_area
Return type

float

abstract property inner_volume
Return type

float

property thickness
Return type

float

property material

Material assigned to the revolve.

Return type

Material

property mass

Calculates the mass of the object as rho * area * thickness, with rho the density of the Material.

Return type

float

property threejs_materials

Definition of the ThreeJS materials that are needed for visualization.

Return type

List[dict]

abstract property threejs_geometries
Return type

List

LineRevolve

class viktor.geometry.LineRevolve(line, *args, material=None, **kwargs)

Bases: viktor.geometry.Revolve

Returns an revolved object of a Line around the global y-axis.

An example revolve of a line between the point (1, 1, 0) and (3, 2, 0) is shown below, with the line object shown in black.

line = Line(Point(1, 1, 0), Point(3, 2, 0))
line_rev = LineRevolve(line)
/_images/line-revolve.png
Parameters
  • line (Line) – Line object which is to be revolved.

  • material (Optional[Material]) – optional material

property line
Return type

Line

property uuid
property height
Return type

float

property surface_area

Returns the total exterior area of the revolved object.

Return type

float

property inner_volume

Returns the inner volume of the revolved object.

This method will only return a value if the defined Line meets the following conditions:

  • it should NOT be horizontal, i.e. y_start != y_end

  • it should be defined in positive y-direction, i.e. y_start < y_end

Return type

float

property geometries

Returns the Line object in format (line, ).

Return type

Tuple[Line, …]

property threejs_geometries

Definition of the ThreeJS objects that are needed for visualization.

Return type

List[dict]

property threejs_object_structure

ThreeJS object structure that is needed for visualization.

Return type

dict

Arc

class viktor.geometry.Arc(centre_point, start_point, end_point, short_arc=True)

Creates a constant radius arc with three Points in the xy plane. Clockwise rotation creates an outward surface.

Parameters
  • centre_point (Point) – Point in xy plane.

  • start_point (Point) – Point in xy plane. Should have same distance to centre_point as end_point.

  • end_point (Point) – Point in xy plane. Should have same distance to centre_point as start_point.

  • short_arc (bool) – Angle of arc smaller than pi if True, larger than pi if False.

property radius
Return type

float

property centre_point
Return type

Point

property start_point
Return type

Point

property end_point
Return type

Point

property theta1

Angle of the end point with respect to the x-axis in radians.

Return type

float

property theta2

Angle of the start point with respect to the x-axis in radians.

Return type

float

property short_arc
Return type

bool

property geometries
Return type

Tuple[Point, Point, Point]

property angle

Absolute angle of the arc in radians, which is the difference between theta1 and theta2.

Return type

float

property length

Arc length.

Return type

float

property theta1_theta2

Calculates the angles of the end (theta1) and start (theta2) points with respect to the x-axis in radians.

Return type

Tuple[float, float]

discretize(num=2)

Returns a discretized representation of the arc, as a list of Point objects. The amount of points can be specified using ‘num’, which should be larger than 1.

Return type

List[Point]

revolve(*, material=None, **kwargs)

Returns an ArcRevolve object, revolved around the global y-axis.

Parameters

material (Optional[Material]) – optional material

Return type

ArcRevolve

ArcRevolve

class viktor.geometry.ArcRevolve(arc, *args, material=None, **kwargs)

Bases: viktor.geometry.Revolve

Returns an revolved object of an arc around the global y-axis.

In the example below, rotation_angle is equal to pi / 3:

/_images/arc-revolve.png

kwargs can consist of:

  • rotation_angle: Angle of the revolve according to the right-hand-rule, with the start of the rotation in positive z-direction. Angle in radians. If not specified, 2 pi will be used.

Parameters
  • arc (Arc) – Arc object.

  • material (Optional[Material]) – optional material

property arc

Arc

property uuid
Return type

str

property surface_area

Total exterior area of the object.

Return type

float

property inner_volume

Returns the inner volume of the revolved object.

This method will only return a value if the defined Arc meets the following conditions:

  • it should be short, i.e. short_arc=True

  • the start- and end-point are located on the same side w.r.t. the y-axis of the center-point of the Arc

  • it is defined in clockwise direction

Return type

float

property height

Height of the object.

Return type

float

property geometries

Returns the Arc object in format (arc,).

Return type

Tuple[Arc]

property threejs_geometries

Definition of the ThreeJS objects that are needed for visualization.

Return type

List[dict]

property threejs_object_structure

ThreeJS object structure that is needed for visualization.

Return type

dict

Triangle

class viktor.geometry.Triangle(point1, point2, point3)
area()
property centroid
property moment_of_inertia

moment of inertia (only in x-y plane)

Type

return

CartesianAxes

class viktor.geometry.CartesianAxes(origin=Point(0.0, 0.0, 0.0), axis_length=1, axis_diameter=0.05)

Bases: viktor.geometry.Group

Helper ThreeJS visualisation object to show positive x (red), y (green) and z (blue) axes.

/_images/cartesian-axes.png
Parameters
  • origin (Point) – Coordinates of the origin.

  • axis_length (float) – Length of the axes.

  • axis_diameter (float) – Diameter of the axes.

RDWGSConverter

class viktor.geometry.RDWGSConverter

Class that provides functions to translate latitude and longitude coordinates between the WGS system and RD system.

The RD coordinate system is a cartesian coordinate system that is frequently used for in civil engineering to describe locations in the Netherlands. The origin is located in france, so that for all of the Netherlands, both x (m) and y (m) values are positive and y is always larger then x. The domain in which the RD coordinate system is valid is:

  • x: [-7000, 300000]

  • y: [289000, 629000]

About the RD coordinate system: https://nl.wikipedia.org/wiki/Rijksdriehoeksco%C3%B6rdinaten

X0 = 155000
Y0 = 463000
phi0 = 52.1551744
lam0 = 5.38720621
static from_rd_to_wgs(coords)

Convert RD coordinates (x, y) to WGS coordinates [latitude, longitude].

lat, lon = RDWGSConverter.from_rd_to_wgs((100000, 400000))
Parameters

coords (Tuple[float, float]) – RD coordinates (x, y)

Return type

List[float]

static from_wgs_to_rd(coords)

Convert WGS coordinates (latitude, longitude) to RD coordinates [x, y].

x, y = RDWGSConverter.from_rd_to_wgs((51.58622, 4.59360))
Parameters

coords (Tuple[float, float]) – WGS coordinates (latitude, longitude)

Return type

List[float]

spherical_to_cartesian

viktor.geometry.spherical_to_cartesian(spherical_coordinates)

Using ISO/physical convention: https://upload.wikimedia.org/wikipedia/commons/4/4f/3D_Spherical.svg

Parameters

spherical_coordinates

Returns

cartesian_to_spherical

viktor.geometry.cartesian_to_spherical(cartesian_coordinates)

Using ISO/physical convention: https://upload.wikimedia.org/wikipedia/commons/4/4f/3D_Spherical.svg

Parameters

cartesian_coordinates

Returns

cylindrical_to_cartesian

viktor.geometry.cylindrical_to_cartesian(cylindrical_coordinates)

Using ISO convention: https://commons.wikimedia.org/wiki/File:Coord_system_CY_1.svg reference plane is former Cartesian xy-plane and cylindrical axis is the Cartesian z-axis

Parameters

cylindrical_coordinates – phi should be between -pi and +pi

Returns

cartesian_to_cylindrical

viktor.geometry.cartesian_to_cylindrical(cartesian_coordinates)

Using ISO convention: https://commons.wikimedia.org/wiki/File:Coord_system_CY_1.svg reference plane is former Cartesian xy-plane and cylindrical axis is the Cartesian z-axis

Parameters

cartesian_coordinates

Returns

azimuth in range [-pi,+pi] rad, +pi chosen over -pi

Extrusion

class viktor.geometry.Extrusion(profile, line, profile_rotation=0, *, material=None)

Bases: viktor.geometry.Group

Extruded object from a given set of points, which is called the profile. This profile should meet the following requirements:

  • start point should be added at the end for closed profile

  • points should be defined in z=0 plane

  • circumference should be defined clockwise

Note that the profile is defined with respect to the start point of the Line object, i.e. the profile is defined in the local coordinate system. An example is given below of two extrusions with the same dimensions. Their corresponding Line objects are also visualized. The extrusion have the following profile:

# black box
profile_b = [
    Point(1, 1),
    Point(1, 2),
    Point(2, 2),
    Point(2, 1),
    Point(1, 1),
]
box_b = Extrusion(profile_b, Line(Point(4, 1, 0), Point(4, 1, 1)))

# yellow box
profile_y = [
    Point(-0.5, -0.5),
    Point(-0.5, 0.5),
    Point(0.5, 0.5),
    Point(0.5, -0.5),
    Point(-0.5, -0.5),
]
box_y = Extrusion(profile_y, Line(Point(2, 2, 0), Point(2, 2, 1)))
/_images/extrusion-profile.png
Parameters
  • profile (List[Point]) – Coordinates of cross-section.

  • line (Line) – A line object is used to define the length (thickness) of the extrusion.

  • profile_rotation (float) – Rotation of the profile around the Z-axis in degrees.

  • material (Optional[Material]) – optional material

property profile
Return type

List[Point]

property material
Return type

Material

property line
Return type

Line

property uuid
Return type

str

property length
Return type

float

property geometries
Return type

Line

property transformation

ArcExtrusion

class viktor.geometry.ArcExtrusion(profile, arc, profile_rotation=0, n_segments=50, *, material=None)

Bases: viktor.geometry.Group

Given an Arc and a cross-section of the extrusion, a discretized Extrusion object is returned.

The coordinates of the profile are defined with respect to the Arc and have a LOCAL coordinate system:

  • z-axis is in direction of the arc from start to end.

  • x-axis is in positive global z-axis.

  • y-axis follows from the right-hand-rule.

Rotation of the profile is about the axis according to the right-hand-rule with LOCAL z-axis (see definition above).

Example:

profile = [
    Point(1, 1),
    Point(1, 2),
    Point(3, 2),
    Point(3, 1),
    Point(1, 1),
]
arc = Arc(Point(1, 1, 0), Point(3, 1, 0), Point(1, 3, 0))
arc_ext = ArcExtrusion(profile, arc, profile_rotation=10, n_segments=10)

This will result in the following visualization, where the Arc itself is also shown in the xy plane:

/_images/arc-extrusion.png
Parameters
  • profile (List[Point]) – Coordinates of cross-section.

  • arc (Arc) – An Arc object is used to define the direction of the extrusion.

  • profile_rotation (float) – Rotation of the profile around its local Z-axis in degrees.

  • n_segments (int) – Number of discretized segments of the arc, which is 50 by default.

  • material (Optional[Material]) – optional material

CircularExtrusion

class viktor.geometry.CircularExtrusion(diameter, line, *, open_ends=False, material=None)

Bases: viktor.geometry.TransformableObject

This class is used to construct an extrusion which has a circular base, e.g. a circular foundation pile.

Parameters
  • diameter (float) – Diameter of the cross-section.

  • line (Line) – Line object along which the circular cross-section is extruded.

  • open_ends (bool) – True if the extrusion ends should be open.

  • material (Optional[Material]) – optional material

property material

Material assigned to the extrusion.

Return type

Material

property line
Return type

Line

property length
Return type

float

property diameter
Return type

float

property radius
Return type

float

property cross_sectional_area
Return type

float

property threejs_geometries

Definition of the ThreeJS objects that are needed for visualization.

Return type

list

property threejs_materials

Definition of the ThreeJS materials that are needed for visualization.

Return type

list

property threejs_object_structure

ThreeJS object structure that is needed for visualization.

Return type

dict

RectangularExtrusion

class viktor.geometry.RectangularExtrusion(width, height, line, profile_rotation=0, *, material=None)

Bases: viktor.geometry.Extrusion

Extruded object from a given set of points, which is called the profile. This profile should meet the following requirements:

  • start point should be added at the end for closed profile

  • points should be defined in z=0 plane

  • circumference should be defined clockwise

Note that the profile is defined with respect to the start point of the Line object, i.e. the profile is defined in the local coordinate system. An example is given below of two extrusions with the same dimensions. Their corresponding Line objects are also visualized. The extrusion have the following profile:

# black box
profile_b = [
    Point(1, 1),
    Point(1, 2),
    Point(2, 2),
    Point(2, 1),
    Point(1, 1),
]
box_b = Extrusion(profile_b, Line(Point(4, 1, 0), Point(4, 1, 1)))

# yellow box
profile_y = [
    Point(-0.5, -0.5),
    Point(-0.5, 0.5),
    Point(0.5, 0.5),
    Point(0.5, -0.5),
    Point(-0.5, -0.5),
]
box_y = Extrusion(profile_y, Line(Point(2, 2, 0), Point(2, 2, 1)))
/_images/extrusion-profile.png
Parameters
  • profile – Coordinates of cross-section.

  • line (Line) – A line object is used to define the length (thickness) of the extrusion.

  • profile_rotation (float) – Rotation of the profile around the Z-axis in degrees.

  • material (Optional[Material]) – optional material

property width

Width of the extrusion.

Return type

float

property height

Height of the extrusion.

Return type

float

property cross_sectional_area

Returns the area of the cross-section (width x height).

Return type

float

property inner_volume

Returns the inner volume of the extruded object.

Return type

float

SquareBeam

class viktor.geometry.SquareBeam(length_x, length_y, length_z, *, material=None)

Bases: viktor.geometry.RectangularExtrusion

High level object to create a rectangular beam object around the origin. The centroid of the beam is located at the origin (0, 0, 0).

Parameters
  • length_x (float) – Width of the extrusion in x-direction.

  • length_y (float) – Length of the extrusion in y-direction.

  • length_z (float) – Height of the extrusion in z-direction.

  • material (Optional[Material]) – optional material

points_are_coplanar

viktor.geometry.points_are_coplanar(points)

Given a set of a minimum of 3 Point objects, determines whether these points can be placed on a two-dimensional plane and hence are coplanar.

Parameters

points (List[Point]) – Points that are to be evaluated.

Return type

bool

lines_in_same_plane

viktor.geometry.lines_in_same_plane(line1, line2)

Method to determine whether two Line objects are located in a shared plane and hence are coplanar.

Parameters
  • line1 (Line) – First line object.

  • line2 (Line) – Second line object.

Return type

bool

calculate_distance_vector

viktor.geometry.calculate_distance_vector(start_point, end_point)

Calculates the distance between start and end point in the direction start -> end.

Parameters
  • start_point (Point) – Start position of the distance vector.

  • end_point (Point) – End position of the distance vector.

Return type

ndarray

convert_points_for_lathe

viktor.geometry.convert_points_for_lathe(points)

Method can be used to convert Point objects to lists of dictionaries in the format: {‘x’: point.x, ‘y’: point.y}

Parameters

points (List[Point]) – Point objects.

Return type

List[dict]

translation_matrix

viktor.geometry.translation_matrix(direction)

Returns the translation matrix that corresponds to a give direction vector (3D).

Parameters

direction (List[float]) – Direction vector of the translation.

Return type

ndarray

scaling_matrix

viktor.geometry.scaling_matrix(scaling_vector)

Returns the scaling matrix that corresponds to a given scaling vector (3D).

Parameters

scaling_vector (List[float]) – Three-dimensional scaling vector.

Return type

ndarray

unit_vector

viktor.geometry.unit_vector(data, axis=None, out=None)

Returns the unit vector of a given vector.

Return type

ndarray

rotation_matrix

viktor.geometry.rotation_matrix(angle, direction, point=None)

Returns the rotation matrix that corresponds to a rotation about an axis defined by a point and direction. Angle in radians, direction in accordance to right hand rule.

Example:

>>> R = rotation_matrix(pi/2, [0, 0, 1], [1, 0, 0])
>>> np.allclose(np.dot(R, [0, 0, 0, 1]), [1, -1, 0, 1])
True
Return type

ndarray

reflection_matrix

viktor.geometry.reflection_matrix(point, normal)

Returns the reflection matrix to mirror at a plane defined by a point and a normal vector.

Parameters
  • point (Point) – Point object.

  • normal (List[float]) – Normal vector of the mirror plane.

Return type

ndarray

mirror_object

viktor.geometry.mirror_object(obj, point, normal)

Function that mirrors an object through a plane. The plane is defined by a point and a normal vector. The return is a copy of the original object, mirrored over the specified plane.

Parameters
  • obj – Object that is to be mirrored

  • point (Point) – Point object on the desired mirror plane

  • normal – Vector that denotes a normal vector of the desired mirror plane.

volume_cone

viktor.geometry.volume_cone(r, h)

Calculates the volume of a cone.

Parameters
  • r (float) – Radius of the base.

  • h (float) – Height of the cone.

Return type

float

surface_cone_without_base

viktor.geometry.surface_cone_without_base(r, h)

Calculates the exterior surface of the cone, excluding the area of the circular base.

Parameters
  • r (float) – Radius of the base.

  • h (float) – Height of the cone.

Return type

float

surface_area_dome

viktor.geometry.surface_area_dome(theta1, theta2, r, R)

Computes the surface area of a dome (arc-revolve).

Parameters
  • theta1 – Starting angle of arc in radians.

  • theta2 – Ending angle of arc in radians.

  • r – Radius of arc.

  • R – Distance from centre of arc to rotation line.

Return type

float

Returns

surface area of arc-revolve.

hex_to_rgb

viktor.geometry.hex_to_rgb(value)

Return (red, green, blue) for the color given as #rrggbb.

Return type

Tuple[int, …]

rgb_to_hex

viktor.geometry.rgb_to_hex(red, green, blue, include_hashtag=True)

Return color as #rrggbb for the given color values.

Return type

str

circumference_is_clockwise

viktor.geometry.circumference_is_clockwise(circumference)
Method determines the direction of a set of points, and returns:
  • True if the circumference is clockwise

  • False if the circumference is counter-clockwise

Parameters

circumference (List[Point]) – Circumference in x,y-plane.

Return type

bool

add_point

viktor.geometry.add_point(unique_points, point)

Adds a Point object to a unique list of Point objects. The point is only added when not already present in the list.

Parameters
  • unique_points (List[Point]) – List of point objects.

  • point (Point) – Point object which has to be added.

Return type

Tuple[List[Point], int]

get_vertices_faces

viktor.geometry.get_vertices_faces(triangles)

Returns the vertices and faces of a list of Triangle objects.

Parameters

triangles (List[Triangle]) – List of triangle objects.

Return type

Tuple[list, list]

find_overlap

viktor.geometry.find_overlap(region_a, region_b, inclusive=False)

Given to regions with upper and lower boundary, check if there is overlap and if so return a tuple with the overlap found

The direction of the given regions does not matter: (1, 2) will be handled exactly the same as (2, 1) The returned Tuple will always be in ascending order

Example usage:

find_overlap((2, 4), (3, 5)) -> (3, 4)
find_overlap((4, 2), (5, 3)) -> (3, 4)
find_overlap((2, 3), (3, 4)) -> None
find_overlap((2, 3), (3, 4), inclusive=True) -> (3, 3)
Parameters
  • region_a (Tuple[float, float]) – Tuple of values of the first region.

  • region_b (Tuple[float, float]) – Tuple of values of the second region.

  • inclusive (bool) – A flag to decide whether a point overlap is counted as overlap or not.

Return type

Optional[Tuple[float, float]]

Returns

A tuple with upper and lower bounds of the overlapping region, or None.

Pattern

class viktor.geometry.Pattern(base_object, duplicate_translation_list)

Bases: viktor.geometry.Group

Instantiates a pattern based on a base object and several duplicates, each translated by an input vector.

Parameters
  • base_object (TransformableObject) – the object to be duplicated

  • duplicate_translation_list (List[List[float]]) – a list of translation vectors, each of which generates a duplicate

property threejs_geometries

Only need to construct the threejs_geometries of the base object. ThreeJS.group_object takes care of positioning the duplicate objects.

Return type

List[List[dict]]

LinearPattern

class viktor.geometry.LinearPattern(base_object, direction, number_of_elements, spacing)

Bases: viktor.geometry.Pattern

Instantiates a linear, evenly spaced, pattern along a single direction.

Parameters
  • base_object (TransformableObject) – the object to be duplicated

  • direction (List[float]) – a unit vector specifying in which direction the pattern propagates

  • number_of_elements (int) – total amount of elements in the pattern, including the base object

  • spacing (float) – the applied spacing

BidirectionalPattern

class viktor.geometry.BidirectionalPattern(base_object, direction_1, direction_2, number_of_elements_1, number_of_elements_2, spacing_1, spacing_2)

Bases: viktor.geometry.Pattern

Instantiates a two-dimensional pattern, evenly spaced in two separate directions

Parameters
  • base_object (TransformableObject) – the object to be duplicated

  • direction_1 (List[float]) – a unit vector specifying the first direction

  • direction_2 (List[float]) – a unit vector specifying the second direction

  • number_of_elements_1 (int) – total amount of elements along direction 1

  • number_of_elements_2 (int) – total amount of elements along direction 2

  • spacing_1 (float) – the applied spacing in direction 1

  • spacing_2 (float) – the applied spacing in direction 2

Polygon

class viktor.geometry.Polygon(points, *, surface_orientation=False, material=None)

Bases: viktor.geometry.TransformableObject

2D closed polygon without holes in x-y plane.

Parameters
  • points (List[Point]) – profile is automatically closed, do not add start point at the end. only the x and y coordinates are considered (z is set to 0). left hand rule around circumference determines surface direction

  • surface_orientation (bool) –

    • if True, the left hand rule around circumference determines surface direction

    • if False, surface always in +z direction

  • material (Optional[Material]) – optional material

Raises

ValueError

  • if less than 3 points are provided.

  • if points contains duplicates.

  • if points form a polygon with self-intersecting lines.

  • if points are all collinear.

has_clockwise_circumference()
Method determines the direction of the input points, and returns:
  • True if the circumference is clockwise

  • False if the circumference is counter-clockwise

Return type

bool

property cross_sectional_area
Return type

float

property centroid

Returns the coordinate of the centroid (geometric center) of the polygon.

Return type

Tuple[float, float]

property moment_of_inertia

Returns the moment of inertia in xy-plane.

Return type

Tuple[float, float]

property material
Return type

Material

property threejs_geometries

Definition of the ThreeJS objects that are needed for visualization.

Return type

list

property threejs_object_structure

ThreeJS object structure that is needed for visualization.

Return type

dict

property threejs_materials

Definition of the ThreeJS materials that are needed for visualization.

Return type

list

Polyline

class viktor.geometry.Polyline(points)

This is a class representing a line made up of multiple straight line segments. It can be created by providing a list of Points. The list of points can be empty or contain duplicate points The line has a directions, following the order of the provided list of points The Polyline class is immutable. All functions that perform changes on a polyline will return a mutated copy of the original polyline

classmethod from_lines(lines)

create a polyline object from a list of lines the end of one line must always coincide with the start of the next

Parameters

lines

Return type

Polyline

Returns

is_equal_to(other)

check if all points in this polyline coincide with all points of another polyline

Parameters

other (Polyline) –

Return type

bool

Returns

property start_point

First point in polyline.points

Return type

Point

Returns

property end_point

Last point in polyline.points

Return type

Point

Returns

property lines

A list of lines connecting all polyline points. Lines between coincident points are skipped.

Return type

List[Line]

property x_min

The lowest x-coordinate present within this polyline

Return type

Optional[float]

Returns

property x_max

The highest x-coordinate present within this polyline

Return type

Optional[float]

Returns

property y_min

The lowest y-coordinate present within this polyline

Return type

Optional[float]

Returns

property y_max

The highest y-coordinate present within this polyline

Return type

Optional[float]

Returns

property z_min

The lowest z-coordinate present within this polyline

Return type

Optional[float]

Returns

property z_max

The highest z-coordinate present within this polyline

Return type

Optional[float]

Returns

get_reversed_polyline()

returns a polyline that is the reverse of this one

Return type

Polyline

Returns

serialize()

return a json serializable dict of form:

>>> [{'x': point_1.x, 'y': point_1.y},
>>>  {'x': point_2.x, 'y': point_2.y}]
Returns

classmethod from_dict(polyline_dict)

Turn a dict generated in the serialize method back into a polyline object

Return type

Polyline

filter_duplicate_points()

Returns a new Polyline object. If a two consecutive points in this polyline coincide, the second point will be omitted

Return type

Polyline

Returns

is_monotonic_ascending_x(strict=True)

Check if the x coordinates of the points of this polyline are ascending.

Parameters

strict (bool) – when set to false, equal x coordinates are accepted between points

Return type

bool

Returns

is_monotonic_ascending_y(strict=True)

Check if the y coordinates of the points of this polyline are ascending

Parameters

strict (bool) – when set to false, equal y coordinates are accepted between points

Return type

bool

Returns

intersections_with_polyline(other_polyline)

Find all intersections with another polyline and return them ordered according to the direction of this polyline

If the polylines are partly parallel, the start and end points of the parallel section will be returned as intersections. If one of the polylines is a subset of the other, or the two lines are completely parallel, no intersection will be found

Parameters
  • other_polyline (Polyline) –

  • inclusive – flag to decide of an intersection of the end of a line segment is counted as well

Return type

List[Point]

Returns

intersections_with_x_location(x)

Find all intersections of this polyline with a given x location. Ordered from start to end of this polyline.

If this line is partly vertical, the start and end points of the vertical section will be returned as a intersection If this line is completely vertical, no intersection will be found.

Parameters

x (float) –

Return type

List[Point]

Returns

point_is_on_polyline(point)

Check if a given point lies on this polyline

Parameters

point

Return type

bool

Returns

get_polyline_between(start_point, end_point, inclusive=False)

Given two points that both lie on a polyline, return the polyline that lies between those two points start_point has to lie before end_point on this polyline.

If the given start point lies after the given end point on this polyline, an empty polyline will be returned If the two given points are identical, it depends on the inclusive flag whether a polyline containing that point once, or an empty polyline will be returned

Parameters
  • start_point (Point) –

  • end_point (Point) –

  • inclusive (bool) – if true, the start and the end points will be added to the returned list

Return type

Polyline

Returns

Raises

ValueError – when one of the two given points does not lie on this polyline

find_overlaps(other)

Find all overlapping regions of this polyline with another polyline. The returned overlapping regions will all point in the direction of this line. The overlap polylines will contain all points of both polylines, even if they only occur in one of the lines.

if no overlaps are found, an empty list will be returned.

Parameters

other (Polyline) –

Return type

List[Polyline]

Returns

combine_with(other)

Given two polylines that have at least one point in common and together form one line without any side branches, combine those two polylines The combined line will contain all points of both polylines.

Parameters

other (Polyline) –

Return type

Polyline

Returns

split(point)

return the two separate parts of this polyline before and after the given point

will raise a value error when the provided point does not lie on this polyline

Parameters

point

Return type

Tuple[Polyline, Polyline]

Returns

classmethod get_lowest_or_highest_profile_x(profile_1, profile_2, lowest)

given two polylines with n intersections, return a third polyline that will always follow the lowest (or highest) of the two lines the x locations of the points of the two polylines should be not descending (lines from left to right or vertical) the returned polyline will only cover the overlapping range in x coordinates

If one of the profiles is an empty polyline, an empty polyline will be returned.

examples:

                                   /----------------|
                                  /         /-------|--------------------
profile_1: ----------------\     /         /        |
                            \   /         /         |_____________________________
profile_2:      -------------\-/         /
                              \_________/

get_lowest_or_highest_profile_x(cls, profile_1, profile_2, lowest=True) will return:


                                           /-------|
                                          /        |
                                         /         |____________________
   result:     -------------\           /
                             \_________/

Note that only the overlapping region of the two profiles is returned!

Parameters
  • profile_1 (Polyline) –

  • profile_2 (Polyline) –

  • lowest (bool) – switch to decide wether to return highest or lowest profile

Return type

Polyline

Returns

Currently, this implementation is exclusive. Meaning that vertical line parts that lie on the start or end of the overlap region in x are not taken into account

Sphere

class viktor.geometry.Sphere(centre_point, radius, width_segments=30, height_segments=30, material=None)

Bases: viktor.geometry.TransformableObject

This class can be used to construct a spherical object around the specified coordinate.

The smoothness of the edges can be altered by setting width_segments and height_segments. In the example below both the default smoothness of 30 (left) and a rough sphere with 5 segments (right) is shown:

/_images/sphere.png
Parameters
  • centre_point (Point) – Center point of the sphere.

  • radius (float) – Radius of the sphere.

  • width_segments (float) – Sets the smoothness in xz-plane.

  • height_segments (float) – Sets the smoothness in yz-plane.

  • material (Optional[Material]) – Optionally a custom material can be set.

diameter()
Return type

float

circumference()
Return type

float

surface_area()
Return type

float

volume()
Return type

float

property threejs_geometries

Definition of the ThreeJS objects that are needed for visualization.

Return type

list

property threejs_object_structure

ThreeJS object structure that is needed for visualization.

Return type

dict

property threejs_materials

Definition of the ThreeJS materials that are needed for visualization.

Return type

list

Torus

class viktor.geometry.Torus(radius_cross_section, radius_rotation_axis, rotation_angle=6.283185307179586, *, material=None)

Bases: viktor.geometry.Group

Create a torus object

Parameters
  • radius_cross_section (float) –

  • radius_rotation_axis (float) – measured from central axis to centre of crosssection

  • rotation_angle (float) – optional argument to control how large of a torus section you want. 2pi for complete torus

  • material (Optional[Material]) – optional material

property inner_volume
property material
Return type

Material

TriangleAssembly

class viktor.geometry.TriangleAssembly(triangles, *, material=None)

Bases: viktor.geometry.TransformableObject

Fundamental visualisation geometry, built up from triangles. Right hand rule on triangle circumference determines the surface direction.

Parameters
  • triangles (List[Triangle]) – Triangles of the assembly.

  • material (Optional[Material]) – optional material

property threejs_geometries
property threejs_object_structure
property threejs_materials

GeoPoint

class viktor.geometry.GeoPoint(lat, lon)

Geographical point on the Earth’s surface described by a latitude / longitude coordinate pair.

This object can be created directly, or will be returned in the parameter set when using a GeoPointField.

Parameters
  • lat (float) – Latitude.

  • lon (float) – Longitude.

classmethod from_rd(coords)

Instantiates a GeoPoint from the provided RD coordinates.

Parameters

coords (Tuple[float, float]) – RD coordinates (x, y).

Return type

GeoPoint

property rd

RD representation (x, y) of the GeoPoint.

Return type

Tuple[float, float]

GeoPolyline

class viktor.geometry.GeoPolyline(*points)

Geographical polyline on the Earth’s surface described by a a list of GeoPoints.

This object can be created directly, or will be returned in the parameter set when using a GeoPolylineField.

Parameters

points (GeoPoint) – Geo points (minimum 2).

property points
Return type

List[GeoPoint]

GeoPolygon

class viktor.geometry.GeoPolygon(*points)

Geographical polygon on the Earth’s surface described by a a list of GeoPoints.

This object can be created directly, or will be returned in the parameter set when using a GeoPolygonField.

Parameters

points (GeoPoint) – Geo points (minimum 3). The profile is automatically closed, so it is not necessary to add the start point at the end.

property points
Return type

List[GeoPoint]