Support Forum

How to find if a 3DLine is on a Face of a Solid Polyhedron or if a 3DPoint is on a 3DLine in Python


See title ...

BIM, BAM, BOOM
BIM-Modelle Tragwerksplaner --> http://www.bimstatik.ch/
My Allplan PythonParts --> https://github.com/BIMStatik/AllplanPythonParts
LinkedIN --> https://ch.linkedin.com/in/bernd-hahnebach-269b855a

Hilfreichste Antwort anzeigen Hilfreichste Antwort verbergen

Hi,

The easy part: to determine whether a 3D point is on a 3D line use DeterminePosition, like:

result = AllplanGeometry.Comparison.DeterminePosition(line, point, 1e-11)

The difficult part: for determining, whether a 3D line is on a face of a polyhedron, I would suggest following steps:
1. Create a 3D polygon out of the face's points.
a. In ALLPLAN 2025 you can get the vertices of any polyhedron's face using PolyhedronUtil.GetFacePoints.
b. In older versions you need to first get all the face's oriented edges, then the edges, then the vertices indices and then the points. Trickier, but possible.
2. Check, whether your 3D line is on the plane defined by the polygon you created. Use IsCoplanar, e.g. like:

AllplanGeo.IsCoplanar(your_polygon.GetPlane(), your_line)

If this is not the case, you can stop the check here.
3. Otherwise, you need to rotate both the line and the polygon, so that they align with XY plane. To do this, you will need a Matrix3D with a rotation from the plane's normal vector to the vector aligned with Z+ (0,0,1). SetRotation is the method you should use.
4. Apply the matrix on your Polygon and 3D line. Now, all the Z coordinates of the line start and end points as well as all the vertices of the polygon should be the same. You can safely convert Polygon3D to 2D (same with your line 3D). For the polygon, you must go point by point, since there is no dedicated method for this. For the line you simply construct a Line2D from a Line3D.
5. Check, whether the line is inside the polygon using Comparison.DeterminePosition

The reason we need to transform and convert to 2D is because the DeterminePosition method can only process 2D polygon and a 2D line.

I know, this might be challenging to implement, yet possible.

Best,
Bart

Hi,

The easy part: to determine whether a 3D point is on a 3D line use DeterminePosition, like:

result = AllplanGeometry.Comparison.DeterminePosition(line, point, 1e-11)

The difficult part: for determining, whether a 3D line is on a face of a polyhedron, I would suggest following steps:
1. Create a 3D polygon out of the face's points.
a. In ALLPLAN 2025 you can get the vertices of any polyhedron's face using PolyhedronUtil.GetFacePoints.
b. In older versions you need to first get all the face's oriented edges, then the edges, then the vertices indices and then the points. Trickier, but possible.
2. Check, whether your 3D line is on the plane defined by the polygon you created. Use IsCoplanar, e.g. like:

AllplanGeo.IsCoplanar(your_polygon.GetPlane(), your_line)

If this is not the case, you can stop the check here.
3. Otherwise, you need to rotate both the line and the polygon, so that they align with XY plane. To do this, you will need a Matrix3D with a rotation from the plane's normal vector to the vector aligned with Z+ (0,0,1). SetRotation is the method you should use.
4. Apply the matrix on your Polygon and 3D line. Now, all the Z coordinates of the line start and end points as well as all the vertices of the polygon should be the same. You can safely convert Polygon3D to 2D (same with your line 3D). For the polygon, you must go point by point, since there is no dedicated method for this. For the line you simply construct a Line2D from a Line3D.
5. Check, whether the line is inside the polygon using Comparison.DeterminePosition

The reason we need to transform and convert to 2D is because the DeterminePosition method can only process 2D polygon and a 2D line.

I know, this might be challenging to implement, yet possible.

Best,
Bart

The fast answer in the regard of methods DetermindPosition helped a lot. For some reason I just did not found it myself. I was exactly what I was looking for.

In the regard of line on face ... Wow long algorithmus ... At the moment I can use the point on line code. But I might need to come back to this. I do not know if I will be that brave to give it a try :-)

Thanks very much for the help,

cheers bernd

BIM, BAM, BOOM
BIM-Modelle Tragwerksplaner --> http://www.bimstatik.ch/
My Allplan PythonParts --> https://github.com/BIMStatik/AllplanPythonParts
LinkedIN --> https://ch.linkedin.com/in/bernd-hahnebach-269b855a

BTW: there are a buch of useful methods here https://pythonparts.allplan.com/2025/api_reference/InterfaceStubs/NemAll_Python_Geometry/Comparison/#NemAll_Python_Geometry.Comparison.DeterminePosition

for example this one I will need soon too ... "Determine the relative position of a point to a Polyhedron"

BIM, BAM, BOOM
BIM-Modelle Tragwerksplaner --> http://www.bimstatik.ch/
My Allplan PythonParts --> https://github.com/BIMStatik/AllplanPythonParts
LinkedIN --> https://ch.linkedin.com/in/bernd-hahnebach-269b855a