Questions similar to this appear on the Bentley Discussion Groups.

Planar Shapes

Planar means that all points of a 3D object have the same Z value: the surface formed by those points is flat. A 3D object may be rotated, which makes the definition of planar a little more complex. One way to test whether an object is planar is to measure its volume: a planar object has zero volume. In 2D, of course, all objects are planar.

Working with MicroStation, we expect shape elements to be planar: they are — or should be — flat. That doesn't mean that they can't be rotated: a shape may be planar in a top, front, side, isometric (ISO) or rotated view.

Here's a screenshot of some shapes used in the VBA project that accompanies this article …

Shape Elements in Top View

In the above screenshot of MicroStation's top view, you can't tell whether those shapes lie on the same plane (are coplanar). The next screenshot of an ISO view shows that they lie on different planes …

Shape Elements in ISO View

A 2D screenshot is not as useful as a 3D DGN model. Download the example project, which contains DGN file shapes.dgn. That file contains the model of which the screenshots above were taken.

Looking at those shapes in MicroStation, you can see that …

Planes and Normals

A plane is defined by its normal and a point on that plane. MicroStation VBA provides the Plane3d user-defined-type (UDT). The two data members of Plane3d are its Normal and Origin.

Shapes, Normals and Planes

A MicroStation VBA ClosedElement, such as a ShapeElement or an EllipseElement, has a Normal property. It's therefore very easy to derive a Plane3d from a ClosedElement. The normal of the plane is the normal of the closed shape, and any point on that closed shape can be the origin of the plane …

Dim oShape As ShapeElement
... get shape from somewhere
Dim plane As Plane3d
plane.Normal = oShape.Normal
plane.Origin = oShape.Vertex (1)

CoPlanar Planes

Two planes may be parallel but not necessarily coplanar. They are parallel if their normals are identical. If they are not parallel then they intersect.

Two planes are coplanar if two conditions are satisfied …

  1. Their normals are identical
  2. A point on one plane also lies on the other plane

VBA Methods to Test Planes

VBA provides many methods that deal with 3D objects. Often, it's hard to work out those methods that will help in a given situation.

In this case, we want first to find whether two planes are coplanar. VBA method Plane3dIntersectsPlane3d tells us if two planes intersect. Therefore, the Boolean inverse of that function tells us whether two planes are parallel …

Dim plane1 As Plane3d
Dim plane2 As Plane3d
... get planes from somewhere
Dim intersectionRay As Ray3d
Dim intersection  As Boolean
intersection = Plane3dIntersectsPlane3d (intersectionRay, plane1, plane2)
Dim parallel As Boolean
parallel = Not intersection

Expressing that test more concisely …

Dim parallel  As Boolean
parallel = Not Plane3dIntersectsPlane3d (intersectionRay, plane1, plane2)

We can test if a point on one plane lies on another plane using VBA method Point3dProjectToPlane3d. If we project the origin of plane 1 onto plane 2 and the result is identical, then the planes must be coplanar. Here's a function to perform that test …

Function TestPlanesCoplanar( _
    ByRef plane0 As Plane3d, ByVal label0 As String, _
    ByRef plane1 As Plane3d, ByVal label1 As String) As Boolean
    TestPlanesCoplanar = False

    Const TrueProjection                    As Variant = 0
    Const ModelCoordinates                  As Boolean = False
    Dim projection                          As Point3d
    projection = Point3dProjectToPlane3d(plane0.Origin, plane1, TrueProjection, ModelCoordinates)
    If Point3dEqual(projection, plane0.Origin) Then
        TestPlanesCoplanar = True
        Debug.Print "Plane" & label0 & " is coplanar with plane" & label1
    Else
        Debug.Print "Plane" & label0 & " is not coplanar with plane" & label1
    End If
End Function

VBA Project to Determine Coplanar Shapes

We wrote some VBA code to help with this problem. The VBA project is available to download. The project includes the VBA source code and a DGN file with a 3D model that contains some coplanar and non-coplanar shape elements.

Use this VBA project to test the 3D DGN model provided. Then, adapt it for your own requirements. Let us know how you get on with the CoPlanar Shapes Project.

Download the CoPlanar Shapes VBA Project

Download a ZIP package that contains the CoPlanarShapes.mvba project and a DGN file shapes.dgn having a 3D model that contains some coplanar and non-coplanar shapes …

Questions

Post questions about MicroStation programming to the MicroStation Programming Forum.