Geometry objects overview
In this chapter we are going to focus on geometry objects, which can be
created using the geometry module NemAll_Python_Geometry
. These will be then
used to create actual Allplan elements, like walls or reinforcement.
To improve the readability of this article, we will organize objects into two categories:
- basic objects - most fundamental geometry objects, which other objects are composed of
- other objects - objects composed by the basic objects
Info
In the code snippets we will be using a shortened name of the module:
AllplanGeo
instead of the full name NemAll_Python_Geometry
.
Import the module like shown below to be able to use the snippets
directly in your code:
Basic objects
Basic objects are the foundation when defining any other geometry object using Allplan Python API. There are only three of them and all are pretty self-explaining.
Angle
Angle object represents an angle. It is used e.g., for rotation operations or defining circular objects, like arc. Its value is given in radians.
Example
angle_1 = AllplanGeo.Angle(math.pi/2) #(1)!
angle_2 = AllplanGeo.Angle.FromDeg(90) #(2)!
print(float(angle_2)) #(3)!
angle_3 = angle_1 + angle_2 #(4)!
- This is how to construct a 90° angle.
- Alternatively we can construct the same angle using degrees.
- Converting the angle object into float will always result in a value in radians.
In this case we will get
1.5707963267948966
. - Angle objects can be i.e., added and subtracted. In this case
angle_3
will represent a 180° angle. Refer to the class documentation to see, what special methods are implemented.
Point
A point is the most basic objects used to compose almost any geometry in Allplan. In a two-dimensional and three-dimensional space, a point is represented by different Python objects. The coordinates are always given in millimeters.
Point2D represents a point in a two-dimensional space.
Example
point_0 = AllplanGeo.Point2D() #(1)!
point_1 = AllplanGeo.Point2D(1000,1000)
point_2 = point_0 + point_1 #(2)!
point_1 /= 2 #(3)!
- This will create a point in (0,0)
- It is possible to move a point by another point. The
point_2
will have the coordinates (1000,1000) - Scaling is also possible. The result of this expression would be
point_1
having following coordinates: (500,500). Refer to the class documentation to see, what special methods are implemented.
Point3D represents a point in a three-dimensional space.
Example
point_0 = AllplanGeo.Point3D() #(1)!
point_2d = AllplanGeo.Point2D(1000,1000)
point_1 = AllplanGeo.Point3D(point_2d) #(2)!
point_2 = point_0 + point_1 #(3)!
point_1 /= 2 #(4)!
- This will create a point in (0,0).
- A point in a 3D space can be constructed out of a 2D point. The z-coordinate is set to zero.
- It is possible to move a point by another point. The
point_2
will have the coordinates (1000,1000,0). - Scaling is also possible. The result of this expression would be
point_1
having following coordinates: (500,500,0). Refer to the class documentation to see, what special methods are implemented.
Vector
A vector is, like the point, also a fundamental geometric object. It defines direction and magnitude. This can be used in operations like translation or scaling, but also to construct other geometric objects. The coordinates are given in millimeters
Vector2D represents a vector in a two-dimensional space.
Example
vector_1 = AllplanGeo.Vector2D(1,1)
vector_2 = vector_1 * 2 #(1)!
vector_3 = AllplanGeo.Vector2D(-1,1)
vector_4 = vector_1 * vector_3 #(2)!
dot_product = vector_1.DotProduct(vector_3) #(3)!
- An example of a multiplication by a scalar.
- With this expression we get the vector cross-product.
Note, that despite multiplicating 2D vectors, the result will be a
Vector3D
(0, 0, 2)
. - To get a dot product, we have to use a dedicated method.
Vector3D represents a vector in a three-dimensional space.
Example
vector_1 = AllplanGeo.Vector3D(1,1,1)
vector_2 = vector_1 * 2 #(1)!
vector_3 = AllplanGeo.Vector3D(-1,1,1)
vector_4 = vector_1 * vector_3 #(2)!
dot_product = vector_1.DotProduct(vector_3) #(3)!
- An example of a multiplication by a scalar.
- With this expression we get the vector cross-product of
(0, -2, 2)
. - To get a dot product, we must use a dedicated method.
Other objects
Using the above-mentioned basic objects, we are able to create any geometry object. Let's go through the most important ones.
Arc
Arc2D is a linear geometry object, that can represent a circular or elliptical arc. It is defined by:
- center point
- two radiuses (major and minor)
- start and end angles
Example
center_point = AllplanGeo.Point2D()
arc = AllplanGeo.Arc2D(center= center_point,
major= 400,
minor= 400,
axisangle= math.pi/6,
startangle= math.pi/4, #(1)!
endangle= math.pi/2,
counterClockwise= False) #(2)!
- The arc angle will result as the difference of end and start angle.
- Optionally we can create the arc in the opposite direction.
Arc3D is a linear geometry object, that can represent a circular or elliptical arc. It is defined by:
- center point
- two radiuses (major and minor)
- start and end angles
- normal vector
Example
center_point = AllplanGeo.Point3D()
dir_x_vector = AllplanGeo.Vector3D(1, 0, 0) #(1)!
norm_vector = AllplanGeo.Vector3D(0, -1, 1) #(2)!
arc = AllplanGeo.Arc3D(center= center_point,
xDir= dir_x_vector,
normVector= norm_vector,
major= 400,
minor= 400,
startAngle= math.pi/6,
deltaAngle= math.pi/2)
- The x-direction vector is where the start angle is measured from.
-
The normal vector defines the direction of the arc according to the right hand rule.
Note
There is no separate object for a circle or ellipse in the Python API. These are just specific cases of a closed arc. Whether an arc is closed, can be checked with the IsClosed method. And with the method IsCircle you can check, whether the arc is elliptical.
Axis
Axis placement
In a two-dimensional space, AxisPlacement2D represents two axes that are orthogonal to each other. Therefore, it can be seen as a local coordinate system. It is defined by:
- reference point
- x-axis direction vector
In a three-dimensional space, AxisPlacement3D represents three axes, which are all orthogonal to each other. Therefore, it can be seen as a local coordinate system. It is defined by:
- origin point
- x-axis direction vector
- z-axis direction vector
Warning
When defining the AxisPlacement3D by X and Z vectors, make sure they are perpendicular to each other. Otherwise the result will be an invalid axis placement object. Whether the constructed AxisPlacement3D object is valid, can be checked with IsValid method.
BRep
BRep3D is a volumetric object that can represent any 3D solid. Refer to the chapter solids to learn more.
Line
Line2D is a linear objects representing, what in geometry is known as line segment in a two-dimensional space. It is defined by start and end point. Because of this, Line2D has a direction, which deviates somewhat from the classic definition of a line segment.
Line3D is a linear objects representing, what in geometry is known as line segment in a three-dimensional space. It is defined by start and end point. Because of this, Line3D has a direction, which deviates somewhat from the classic definition of a line segment.
Plane
Plane3D represents a plane in a three-dimensional space. It can be defined by:
- point and a normal vector
- three points
Polygon
Polygon2D is an areal object representing a polygon in a two-dimensional space. Unlike Polyline2D, it represents a closed geometric shape and therefore you can tell its inside and outside as well as calculate its area.
Polygon3D is an areal object representing a polygon in a three-dimensional space. Unlike Polyline3D, it represents a closed geometric shape and therefore you can tell its inside and outside as well as calculate its area.
Warning
Three-dimensional polygon is a planar object! Therefore, all points defining a 3D polygon must be coplanar. Otherwise, the constructed polygon will be invalid. Whether a polygon is valid, can be checked with the methods IsValid and IsValidStatus. The second one returns also the reason of invalidity.
When constructing a polygon, the following rules must be fulfilled:
- It does not 'auto-close' itself: polygon with 4 vertices must be defined by 5 points, last point being equal to first one.
- Points' orientation must be monotonous. It can be either clockwise or counterclockwise.
- It must not self-intersect itself. Otherwise, some methods will report errors or return wrong calculation results.
Tip
A polygon can be compound from one or more loops. A loop can represent a solid element or a hole element, depending on the orientation of the loop: if solid element is oriented counterclockwise, a hole must be oriented clockwise (see example below). Each loop must be closed (first and last point must be equal).
Example
In this example we will construct a polygon with an opening in the middle. The principles shown here apply to both Polygon2D and Polygon3D.
# create outer polygon
solid_polygon = AllplanGeo.Polygon3D()
solid_polygon += AllplanGeo.Point3D(-2,-2, 0) #(1)!
solid_polygon += AllplanGeo.Point3D(4, -2, 0)
solid_polygon += AllplanGeo.Point3D(8, 2, 0)
solid_polygon += AllplanGeo.Point3D(6, 6, 0)
solid_polygon += AllplanGeo.Point3D(2, 10, 0)
solid_polygon += AllplanGeo.Point3D(-4, 4, 0)
solid_polygon += solid_polygon.Points[0] #(2)!
# create opening
opening_polygon = AllplanGeo.Polygon3D() #(3)!
opening_polygon += AllplanGeo.Point3D(4, 5, 0)
opening_polygon += AllplanGeo.Point3D(3, 1, 0)
opening_polygon += AllplanGeo.Point3D(1, 1, 0)
opening_polygon += AllplanGeo.Point3D(0, 3, 0)
opening_polygon += opening_polygon.Points[0]
solid_polygon.InsertPolygon(opening_polygon,
position= len(polygon.Points)) #(4)!
- Polygon3D inherits from PolyPoints3D, which makes it possible to add a point using the augmented assignment operator.
- Polygon does not auto-close, therefore we append its first point at the end to close it
- In this example we create the hole polygon as a new object. Note, that its orientation is clockwise, unlike the orientation of the solid polygon
- Here we can append the hole polygon at the end of the solid polygon
Polyhedron
Polyhedron3D is a volumetric object that can represent any 3D solid. Refer to the chapter solids to learn more.
Polyline
Polyline2D is a linear object representing, what in geometry is known as polygonal chain . It is defined by a sequence of Point2D. Unlike Polygon2D, a polyline doesn't have to be closed, as it does not represent a closed shape. It has no inside or outside and you cannot calculate its area.
Polyline3D is a linear object representing, what in geometry is known as polygonal chain . It is defined by a sequence of Point3D. Unlike Polygon3D, a polyline doesn't have to be closed, as it does not represent a closed shape. It has no inside or outside and you cannot calculate its area. Its points don't have to be coplanar.
Spline
Spline2D is a linear object representing a spline in a two-dimensional space. It is defined by a sequence of Point2D. Optionally, a tangent vector can be set at the start and/or end of the spline.
Example
spline = AllplanGeo.Spline2D()
spline += AllplanGeo.Point2D()
spline += AllplanGeo.Point2D(5, 1)
spline += AllplanGeo.Point2D(8, 8)
spline += AllplanGeo.Point2D(5, 7)
spline += AllplanGeo.Point2D(1, 4)
spline += AllplanGeo.Point2D(0, 9)
spline.StartVector = AllplanGeo.Vector2D(1,-1) #(1)!
spline.EndVector = AllplanGeo.Vector2D(1,1)
- Setting a tangent vector is optional.
Spline3D is a linear object representing a spline in a three-dimensional space. It is defined by a sequence of Point3D. Optionally, a tangent vector can be set at the start and/or end of the spline.
Example
spline = AllplanGeo.Spline3D()
spline += AllplanGeo.Point3D()
spline += AllplanGeo.Point3D(5, 1, 2)
spline += AllplanGeo.Point3D(8, 8, 5)
spline += AllplanGeo.Point3D(5, 7, 6)
spline += AllplanGeo.Point3D(1, 4, 3)
spline += AllplanGeo.Point3D(0, 9, 0)
spline.StartVector = AllplanGeo.Vector3D(1, -1, 1) #(1)!
spline.EndVector = AllplanGeo.Vector3D(1, 1, -1)
- Setting a tangent vector is optional.