Please ensure Javascript is enabled for purposes of website accessibility
Powered by Zoomin Software. For more details please contactZoomin

Hull and Outfitting

Geometry

  • Last UpdatedNov 24, 2023
  • 13 minute read

These python classes handles different kinds of geometry.

Class KcsPoint2D.Point2D

The class holds information about a 2D point. It is the basic class for Vitesse 2D operations.

Parameters and attributes:

X

real

x-coordinate of the point

Y

real

y-coordinate of the point

Constructor:

Point2D (<x>, <y>)

This constructor will create instance of Point2D class. Parameters are defined as above, default values are zeros.

Methods:

DistanceToPoint(p)

real

Calculates straight line distance between point and second point given as parameter.

p

Point2D

Point to get distance to

Move (xmove, ymove)

Translates the point by given values

xmove

real

Change in x-coordinate

ymove

real

Change in y-coordinate

Round (decimals)

Rounds coordinate values to a given number of decimals.

Example:

p = Point2D(103.67,203.73)

p.Round(1)

print p # [X Y:103.7,203.7]

decimals

integer

Number of decimals to round to

SetFromPoint (p)

Set point as a copy of other point

p

Point2D

Point to copy coordinates from

SetFromMidpoint (p1, p2)

Update the point to be the midpoint of two other points

p1

Point2D

First point

p2

Point2D

Second point

SetCoordinates(x,y)

Update point coordinates. Parameters are defined as attributes above.

Class protocols:

__repr__

Used to return string representation of Point2D object

__cmp__

Used to compare two Point2D objects

 

Example:

point = KcsPoint2D.Point2D(10.0,0.0)

Class KcsVector2D.Vector2D(X,Y)

The class holds information about a 2D vector.

Parameters and attributes:

X

real

x-coordinate of the vector

Y

real

y-coordinate of the vector

Methods:

SetFromVector

SetLength

SetFromPoints

BlankProduct

CompareVector

SetFromVectorDifference

DotProduct

SetComponents

Length

LargestComponentAxis

Rotate

Round

ScalarComponentOnVector

SetFromVectorSum

SetToUnitVector

Example:

vec = KcsVector2D.Vector2D(1.0,0.0)

Class KcsRline2D.Rline2D(Start,End)

The class holds information about a restricted 2D line.

Parameters and attributes:

Start

Point2D

Start point of the line

End

Point2D

End point of the line

Methods:

None

Examples:

sp   = KcsPoint2D.Point2D(0.0,0.0)
ep   = KcsPoint2D.Point2D(100.0,100.0)
line = KcsRline2D.Rline2D(sp,ep)

Class KcsRectangle2D.Rectangle2D(Corner1,Corner2)

The class holds information about a 2D axis-parallel rectangle.

NB: The rectangle is defined by two opposite corners.

Parameters and attributes:

Corner1

Point2D

First corner of the rectangle

Corner2

Point2D

Second corner of the rectangle

Methods:

None

Examples:

c1 = KcsPoint2D.Point2D(0.0,0.0)
c2 = KcsPoint2D.Point2D(100.0,100.0)
rectangle = KcsRectangle2D.Rectangle2D(c1,c2)

Class KcsArc2D.Arc2D

The class holds information about a 2D arc segment. It is used in many Vitesse classes and functions that means, arc_new, arc_highlight and dim_diameter_new in module kcs_draft.

Parameters and attributes:

Start

Point2D

Start point of the arc segment

End

Point2D

End point of the arc segment

Amplitude

real

Amplitude of the arc segment

Constructor:

Arc2D (start, end, amplitude)

This constructor will create instance of Arc2D class. Parameters are defined as above.

Methods:

None

Class protocols:

__repr__

Used to return string representation of Arc2D object.

 

Examples:

sp = KcsPoint2D.Point2D(0.0,0.0)
ep = KcsPoint2D.Point2D(100.0,100.0)
ampl = 30.0
arc = KcsArc2D.Arc2D(sp,ep,ampl)

arc.Amplitude = 40

Class KcsCircle2D.Circle2D

The class holds information about a 2D circle. It is used in Vitesse kcs_draft module functions that means, dim_diameter_new, circle_new or circle_highlight.

Parameters and attributes:

Centre

Point2D

Centre of the circle

Radius

real

Radius of the circle

Constructor:

Circle2D (centre, radius)

This constructor will create instance of Circle2D class. Parameters are defined as above.

Methods:

HasPoint (point)

integer

Checks whether given point is inside the circle:

1 – point is inside the circle

0 – point is outside the circle or it is on the circle

point

Point2D

Point to test.

IsPointOnCircle (point)

integer

Checks whether given point is on the circle:

1 – point is on the circle

0 – point is inside or outside the circle

point

Point2D

Point to test

GetTangentPoints (tngPnt1, <tngPnt2>, <cle>)

Point2D

or

[ Point2D, Point2D ]

No optional parameters given:

Method gets possible tangent points. Each of two returned tangent points on the circle and a point tngPnt1 outside the circle defines tangent to the circle. If tngPnt1 is on the circle, method returns only one point equal to tngPoint1.

Optional parameters given:

Method returns one tangent point of the master circle and one tangent point of circle <cle>, both lying on one common tangent of two circles. Points tngPnt1 and tngPnt2 define which variant of tangential line is considered (resulting points are possibly closest to given).

tngPnt1

Point2D

A point outside the circle essential for main circle tangent point(s) calculation

<tngPnt2>

Point2D

An approximate tangent point to circle <cle> for common tangent calculation.

<cle>

Circle2D

Second circle for common tangent calculation

TangentAtPoint (pntExt, pntRef)

Vector2D

Method returns a vector which is a tangent to circle through point pntExt and the tangent point closest to approximate point pntRef selected by the user.

pntExt

Point2D

A point outside the circle

pntRef

Point2D

A point on the circle defining tangent vector variant

Class protocols:

__repr__

Used to return string representation of Circle2D object.

Examples:

cp = KcsPoint2D.Point2D(100.0,100.0)
rad = 50.0
circle = KcsCircle2D.Circle2D(cp,rad)

Class KcsEllipse2D.Ellipse2D(Corner1,Corner2)

The class holds information about a 2D ellipse circumscribed by a rectangle.

NB: The circumscribing rectangle is defined by two opposite corners.

Parameters and attributes:

Corner1

Point2D

First corner of the circumscribing rectangle

Corner2

Point2D

Second corner of the circumscribing rectangle

Methods:

Examples:

c1 = KcsPoint2D.Point2D(100.0,100.0)
c2 = KcsPoint2D.Point2D(400.0,400.0)
ellipse = KcsEllipse2D.Ellipse2D(c1,c2)

Class KcsPolygon2D.Polygon2D

The class holds information about a 2D polygon. Polygon is represented as a list of points. Polygons are used in Vitesse functions that means, note_new() in module kcs_draft.

Parameters and attributes:

Polygon

[ Point2D ]

List of polygon points. Access to list is possible also by class protocols __len__, __getitem__ and __setitem__

Constructor:

Polygon2D(<startp>)

This constructor will create instance of Point2D class. If startp is not None, it initiates the list of polygon points in Polygon attribute.

<startp>

Point2D

Start point of the polygon. None by default

Methods:

AddPoint(nextp)

Adds a point at the end of the polygon

nextp

Point2D

The next point of the polygon

Class protocols:

__repr__

Used to return string representation of Polygon2D object

__cmp__

Used to compare two Polygon2D objects

__len__

Used to return the length of polygon (number of points in Polygon attribute)

__getitem__

Implements sequence type evaluation of self[key] to Point2D

__setitem__

Implements sequence type assignment of Point2D to self[key]

 

Examples:

sp = KcsPoint2D.Point2D(100.0,50.0)
polygon = KcsPolygon2D.Polygon2D(sp)
sp.X = 30.0
sp.Y = 120.0
polygon.AddPoint(sp)
sp.Y = 400.0
polygon.Addpoint(sp)

point = polygon[1]

Class KcsContour2D.Contour2D

The class holds information about contour. It is used in Vitesse functions, that means, contour_properties_get and hatch_new in module kcs_draft or pan_curve_create in module kcs_hull.

Parameters and attributes:

Contour

[segment]

List of contour segments. Each segment is a list of one or two arguments. The syntax is [startPoint, <amplitude>] where:

startPoint - Point2D at the end of the segment

amplitude - amplitude at the midpoint of segment (if 0 or none then segment is a straight line)

First segment always consists of one point only. The point is a start point of contour.

Visible

integer

Visibility:

1 : contour is visible

0 : contour is not visible.

Detectable

integer

Detect ability:

1 : contour is detectable

0 : contour is not detectable.

Colour

Colour

Colour of contour

LineType

LineType

Line type of contour. Line type must be defined in system.

Layer

Layer

Layer of contour

Constructor:

Contour2D (startp)

This constructor will create an instance of Contour2D class

startp

Point2D

Start point of the contour

Methods:

AddLine (point)

Add a line (straight) segment to the contour

point

Point2D

Point at end of line

AddArc (point, amplitude)

Add an arc segment to the contour

point

Point2D

Point at the end of the arc

amplitude

real

Amplitude at the midpoint of segment

SetPoint (point)

Reset the contour to one point

point

Point2D

Start point of the contour

IsPoint ()

integer

Checks if contour is a point:

1 - Contour is a point

0 - Contour is not a point

IsClosed ()

integer

Check whether the contour is closed:

1 - Contour is closed

0 - Contour is not closed

IsInside (point)

integer

Check whether the point is inside the contour:

1 - The point is inside the contour

0 - The point is outside or on the contour or the contour is not closed.

point

Point2D

Point to test

IsPointOnContour (point)

integer

Check whether the given point is on contour:

1 - The point is on the contour

0 - The point is not on the contour.

point

Point2D

Point to test

GetPointOnContour (point)

Get a point on contour, which is nearest to the given point. New point is returned in input variable.

point

Point2D

Input/output point

GetCenterPoint (start, end, amplitude)

Point2D

Get the center point of a segment given at input

start

Point2D

Start point of the segment

end

Point2D

End point of the segment

amplitude

real

Amplitude of the segment

Distance (point)

real

Get the distance between given point on contour and the end point of the contour measured along contour

point

Point2D

Point on contour, whose distance to end point is to be calculated

Length()

real

Get the length of contour

Area()

real

Get the area inside contour

Direction()

integer

Get the direction (orientation) of the contour:

-1 - Contour is clockwise

-1 - Contour is anticlockwise

Class protocols:

__repr__

Used to return string representation of Contour2D object.

__add__

Returns a sum of two contours, for example:

contC = contA + contB

Now contC is a new instance of Contour2D representing the sum of contA and contB where contA and contB are also instances of Contour2D.

__sub__

Returns a subtraction of two contours, for example:

contC = contA - contB

Now contC is a new instance of Contour2D representing the subtraction of contA and contB where contA and contB are also instances of Contour2D.

__mul__

Returns a common part of two contours, for example:

contC = contA * contB

Now contC is a new instance of Contour2D representing the common part of contA and contB where contA and contB are also instances of Contour2D.

Class KcsContourOperations. BooleanOperations:

The ContourOperations class holds information about two 2D dimensional# contours, which will be used to perform operations on.

Attributes:

__contour1

Contour2D

First contour

__contour2

Contour2D

Second contour

__segments1

list

Segments list of first contour

__segments2

list

Segments list of second contour

Methods:

BooleanOperations(constructor)

Creates an instance of the class

INPUT:

Contour2D

First contour

Contour2D

Second contour

ConvertContour

Converts contour segments to the following representation:

(start point, end point, center point, amplitude)

INPUT:

Contour2D

Contour to convert

GetInsideSegments

Gets all segments that are inside the other contour.

INPUT:

list

List of segments converted by ConvertContour

GetOuterSegments

Gets all segments that are outside the other contour

INPUT:

list

List of segments converted by ConvertContour

GetConditionalSegments

Gets all segments that are in both contours.

INPUT:

list

List of segments converted by ConvertContour

IsOuterSegment

Checks if segment is an outer segment.

INPUT:

list

Segment converted by ConvertContour

IsOuterPoint

Checks if point is an outer point.

INPUT:

Point2D

Point

ChooseNextSegment

Chooses next segment used for adding contours.

INPUT:

list

Segment converted by ConvertContour

list

List of priority segments converted by ConvertContour

list

List of secondary segments converted by ConvertContour

DifferNextSegment

Chooses next segment used for subtracting contours.

INPUT:

list

Segment converted by ConvertContour

list

List of priority segments converted by ConvertContour

list

List of secondary segments converted by ConvertContour

CompositeContour

Adds contours

INPUT:

list

List of intersection points

ChooseDifStartPoint

Chooses another start point when creating more than one contour.

INPUT:

list

list of already used segments converted by ConvertContour

list

list of segments converted by ConvertContour

CommonContour

Finds common part(s) of two contours

INPUT:

list

list of intersection points

DifferContour

Subtracts contours.

list

list of intersection points

Class KcsConic2D.Conic2D

The class holds information about a 2D conic segment. It is used in Vitesse kcs_draft module functions, that means, conic_new or conic_highlight

Parameters and attributes:

Start

Point2D

The start point

End

Point2D

The end point

Amplitude

Vector2D

The amplitude vector

Cff

real

The form factor. It controls the shape of the conic and should be 0 <= Cff < 1. In mathematical terms, a value < 0.5 will yield a ellipse, a value > 0.5 a hyperbola, while a value of exactly 0.5 will yield a parabola.

Constructor:

Conic2D (stp, endp, ampl, cff)

This constructor will create instance of Conic2D class. Parameters are defined as above.

Methods:

None

Class protocols:

__repr__

Return string representation of Conic2D object

 

Examples:

sp = KcsPoint2D.Point2D(100.0,100.0)
ep = KcsPoint2D.Point2D(300.0,300.0)
amp = KcsVector2D.Vector2D(1.0,2.0)

cff = 0.1
con = KcsConic2D.Conic2D(sp,ep,amp,cff)

Class KcsPoint3D.Point3D

The class holds information about a 3D point. It is the basic class for Vitesse 3D operations.

Parameters and attributes:

X

real

x-coordinate of the point

Y

real

y-coordinate of the point

Z

real

z-coordinate of the point

Constructor:

Point3D (<x>, <y>, <z>)

This constructor will create instance of Point3D class. Parameters are defined as above, default values are zeros.

Methods:

DistanceToPoint(p)

real

Calculates straight line distance between point and second point given as parameter

p

Point3D

Point to get distance to

Round (decimals)

Rounds coordinate values to a given number of decimals.

Example:

p = Point3D(103.67,203.73, 300)

p.Round(1)

print p # [X Y:103.7,203.7, 300.0]

decimals

integer

Number of decimals to round to

SetFromPoint (p)

Set point as a copy of other point

p

Point3D

Point to copy coordinates from

SetFromMidpoint (p1, p2)

Update the point to be the midpoint of two other points

p1

Point3D

First point

p2

Point3D

Second point

SetCoordinates(x,y,z)

Update point coordinates. Parameters are defined as attributes above.

Transform (tra)

Transform the point using a transformation matrix

tra

Transformation3D

Transformation matrix

Class protocols:

__repr__

Used to return string representation of Point3D object

__cmp__

Used to compare two Point3D objects

 

Example:

point = KcsPoint3D.Point3D(0.0,0.0,0.0)

Class KcsVector3D.Vector3D

The class holds information about vector 3D.

Attributes:

X

Float

X-coordinate

Y

Float

Y-coordinate

Z

Float

Z-coordinate

Methods:

Class constructor:

This constructor will create instance of Vector3D class.

Vector3D(<x>, <y>, <z>)

Coordinates are optional. Default value for all coordinates is:

-32000

AngleToVector(v1)

Returns angle (in radians) between self and another vector 3D v1.

AngleToVectorWithSign(v1)

Returns angle (in radians) between self and another vector 3D v1 with sign.

BlankProduct (scale)

Scale the vector length by scale value.

BoxProduct (v1, v2)

Calculates the box product between self and other two vectors v1 and v2.

CompareVector(v1, tol)

Compares with another vector v1 and tolerance tol.

DotProduct (v1)

Returns scalar product between self and vector v1.

AbsoluteLargestComponentAxis()

Returns axis with largest component absolute value. It returns:

0 for X axis,

1 for Y axis and

2 for Z axis.

Length ()

Returns length of vector.

ProjectOnLine(line3D)

Projects vector on Line3D

ProjectOnVector(v1)

Projects vector on another 3D vector v1.

ProjectOnPlane(plane)

Projects vector on Plane3D.

Rotate(angle, v1)

Rotates vector by given angle (in radians) around another vector.

Round(decimals)

Rounds vector components to given number of decimals.

ScalarComponentOnLine(line)

Performs scalar projection on Line3D.

SetComponents(x, y, z)

Sets vectors components.

SetFromCrossProduct(v1, v2)

Sets vectors components from cross product of another two vectors v1 and v2.

SetFromPoints(p1, p2)

Sets vectors components from start and end 3D points p1 and p2.

SetFromVector(v1)

Sets vectors components from another 3D vector v1

SetFromVectorDifference(v1, v2)

Sets vectors components to difference of another two 3D vectors: v1-v2.

SetFromVectorSum(v1, v2)

Sets vectors components to sum of another two 3D vectors: v1+v2.

SetLength(length)

Update the vector to have a certain length.

SetToUnitVector()

Update the length of vector to 1.

Transform(tra)

Transforms vector by Transformation3D matrix.

Operators

Operators: ==, !=, <=, <, >, >=, +, -, truth value testing

Sequential data type protocol

You can use index for accessing vector components:

v1[0] returns X component,

v1[1] returns Y component,

v1[2] returns Z component.

Example:

from KcsPoint3D import Point3D

v1 = Point3D(12, 22, 24)

v1[v1.AbsolutLargestComponentAxis()] = 0.0

print v1

Class KcsLine3D.Line3D(Point,Direction)

The class holds information about an unlimited 3D line

Parameters and attributes:

Point

Point3D

A point on the line

Direction

Vector3D

A vector along the line

Methods:

ScalarComponentOfVector

VectorComponentOfVector

Transform

Examples:

pnt = KcsPoint3D.Point3D(100.0,100.0,100.0)

dir = KcsVector3D.Vector3D(0.0, 0.0, 1.0)

line = KcsLine3D.Line3D( pnt, dir)

Class KcsPolygon3D.Polygon3D(Start)

The class holds information about a 3D polygon.

Parameters:

Start

Point3D

Start point of the polygon

Methods:

AddPoint

ClassPolygon3D.GetNoOfPoints()

The function returns number of points in polygon.

ClassPolygon3D.GetPoint()

The function returns Point3D instance of polygon point selected by index (0 based).

Examples:

sp = KcsPoint3D.Point3D(100.0,50.0,0.0)
polygon = KcsPolygon3D.Polygon3D(sp)
sp.X = 30.0
sp.Y = 120.0
polygon.AddPoint(sp)
sp.Y = 400.0
polygon.Addpoint(sp

Class KcsPlane3D.Plane3D)

The class holds information about an unlimited plane. It is used by Vitesse functions i.e view_slice_planes_get() in module kcs_draft.

Parameters and attributes:

Point

Point3D

A point on the plane

Normal

Vector3D

A vector perpendicular to the plane

Constructor:

Plane3D (pnt, norm)

This constructor will create instance of Plane3D class. Parameters are defined as above.

Methods:

IntersectLine (line, point)

integer

Intersects the plane with a line. If the intersection is found it returns 0 and sets "point" parameter to intersection point, otherwise returns –1.

line

Line3D

The line to intersect the plane with

point

Point3D

The point to be updated with result

Transform (tra)

Transforms a plane using transformation matrix.

tra

Transformation3D

The transformation matrix

Class protocols:

__repr__

Used to return string representation of Plane3D object.

 

Examples:

pnt = KcsPoint3D.Point3D(0.0,0.0,0.0)
norm = KcsVector3D.Vector3D(0.0, 1.0, 0.0)
plane = KcsPlane3D.Plane3D( pnt, norm)

Class KcsCircle3D.Circle3D

The class holds information about a 3D circle.

Parameters and attributes:

Centre

Point3D

Centre of the circle

Normal

Vector3D

Normal vector to circle plane

Radius

real

Radius of the circle

Constructor:

Circle3D (centre, normal, radius)

This constructor will create instance of Circle3D class. Parameters are defined as above.

Class protocols:

__repr__

Used to return string representation of Circle3D object.

Examples:

cp = KcsPoint3D.Point3D(100.0,100.0, 50.0)
rad = 50.0

norm = KcsVector3D.Vector3D(0,0,1)
circle = KcsCircle2D.Circle2D(cp,norm,rad)

Class KcsBox.Box

The class holds information about a 3D box. It is used that means, with classes KcsAssembly.Assembly, KcsVolPrimitiveBlock.VolPrimitiveBlock or with function view_symbolic_new in module kcs_draft.

Parameters and attributes:

Origin

Point3D

Box origin

LengthDir

Vector3D

Length direction vector

HeightDir

Vector3D

Height direction vector

Length

real

Length along ‘LengthDir’ vector

Height

real

Height along ‘HeightDir’ vector

Width

real

Width along right normal of "length-height" plane

Constructor:

Box (origin, lengthDir, heightDir, length, height, width)

This constructor will create instance of Box class. Parameters are defined as above.

Methods:

SetAxisParallelBox (lowCorner, upCorner) or

(x1, y1, z1, x2, y2, z2)

It will create axis parallel box. Height direction is parallel to Y axis and Length direction is parallel to Z axis.

lowCorner

Point3d

Lower-left (min z) corner of Bo

upCorner

Point3d

Upper-right (max z) corner of Box

x1, y1, z1, x2, y2, z2

real

Corners in coordinate list format (first = lower-left, second = upper-right)

IsEmpty()

integer

1 - Box is empty (three dimensions are equal 0)

0 - Box is not empty

Class protocols:

__repr__

Used to return string representation of Box object.

 

Examples:

import KcsBox

import KcsPoint3D

import KcsVector3D

origin = KcsPoint3D.Point3D(0,0,0)
lengthDir = KcsVector3D.Vector3D(0,1,2)

heightDir = KcsVector3D.Vector3D(0,2,1)
box = KcsBox.Box(origin, lengthDir, heightDir, 45.7 , 10, 55.5)

Class KcsCap.Cap

The class holds information about a cap. The cap primitive describes a spherical segments, that means, a part of a sphere, cut off with plane.

Parameters and attributes:

Origin

Point3d

Cap origin

Direction

Vector3d

Cap direction vector

Diameter

real

Cap diameter

Amplitude

real

Cap amplitude

Constructor:

Cap (orig, dir, diam, ampl)

This constructor will create instance of Cap class. Parameters are defined as above.

Class protocols:

__repr__

Return string representation of Cap object.

 

Examples:

import KcsCap

import KcsPoint3D

import KcsVector3D

origin = KcsPoint3D.Point3D(4,5,7.8)

direction = KcsVector3D.Vector3D(0,0,1)

cap = KcsCap.Cap(origin, direction, 4, 7.8)

cap.Diameter = 1

Class KcsCone.Cone

The class holds information about a cone. For the cone primitive at least one of the two defining radii must be greater than zero.

Parameters and attributes:

Origin

Point3D

Cone origin (centre of first end circle)

Direction

Vector3D

Cone direction vector

Length

real

Cone length.

Diameter1

real

The diameter of first end circle

Diameter2

real

The diameter of second end circle

Constructor:

Cone (orig, dir, len, diam1, <diam2>)

This constructor will create instance of Cone class. Parameters are defined as above, by default <diam2> is equal to diam1. At least one of the diameters must be greater then zero.

Class protocols:

__repr__

Return string representation of Cone object.

 

Example:

origin = KcsPoint3D.Point3D(4,5,7.8)

direction = KcsVector3D.Vector3D(0,0,1)

cone = KcsCone.Cone(origin, direction, 20, 8, 0)

cone.Diameter2 = 1

Class KcsConnection.Connection

The class holds information about a connection.

Parameters and attributes:

Pos

Point3D

Origin of the connection

Dir

Vector3D

Direction of the connection

Type

integer

The type of the connection (1-9)

Number

integer

The number of the connection (1-199)

Descr

string

The description of the connection

Constructor:

Connection (pos, dir, type, number, <descr>)

This constructor will create an instance of Connec\-tion class. Parameters are defined as above, description is an empty string by default.

Class protocols:

__repr__

Return string representation of Connection object.

 

Examples:

pos = KcsPoint3D.Point3D(100.0,100.0, 0.0)
dir = KcsVector3D.Vector3D(1.0,2.0,3.0)
con = KcsConnection.Connection(pos, dir, 1, 50, ‘description’)

Related Links
TitleResults for “How to create a CRG?”Also Available in