Questions similar to this appear on the Be Community Forums. This problem appeared in the MicroStation Programming Forum.

This article answers questions about points, vectors derived from points, and computations you can make using vectors to determine their spatial relationships.

Q Using MicroStation VBA, how do I …

Vector 'left' of vector Vector 'right' of vector

Vectors and Points

A point (VBA Point3d) is a location in a 3D coordinate system. A point has no length and no direction. A vector (VBA Vector3d) is a line between two points. It has a length and a direction.

Because a vector has a direction, it's valid to ask a question about direction. Given two vectors V1 and V2, for example …

MicroStation VBA has answers to all the above questions.

Given two points, you can construct the vector between them like this …

Dim point1 As Point3d
'  Get point1 from somewhere
Dim point2 As Point3d
'  Get point2 from somewhere
Dim vector As Vector3d
vector = Vector3dSubtractPoint3dPoint3d (point1, point2)

A Measure Angle Between Vectors

MicroStation VBA provides the Vector3dAngleBetweenVectors method. Use it like this …

Dim vector1 As Vector3d
'  Get vector1 from somewhere
Dim vector2 As Vector3d
'  Get vector2 from somewhere
Dim radians As Double
radians = Vector3dAngleBetweenVectors (vector1, vector2)

A A Practical use for the Cross-Product of two Vectors

MicroStation VBA provides the Vector3dCrossProduct3Points and Vector3dCrossProductXY methods.

Dim vector1 As Vector3d
'  Get vector1 from somewhere
Dim vector2 As Vector3d
'  Get vector2 from somewhere
Dim cross As Double
cross = Vector3dCrossProductXY (vector1, vector2)
If (cross > 0) Then
  '  Vector1 is rotated clockwise from vector2
Else If (cross < 0) Then
  '  Vector1 is rotated counter-clockwise from vector2
EndIf

A Determine whether a Point is to the Left or Right of Another Point

Construct two vectors from a common point to each of the two points. Compare the vectors' orientation by computing their cross-product.

Use the cross-product of two vectors to find their relative orientation. The magic of linear algebra!

PointOrientation VBA Project

The PointOrientation VBA Project assembles the above fragments into a working macro. The project is not protected, so you can both execute it to see how it works and examine the source code to see how it's implemented.

Example VBA Project

The PointOrientation VBA Project is a complete example.

Download VBA Project

Download the PointOrientation project, which is in a ZIP archive. Extract PointOrientation.mvba to a well-known location, such as folder ..\Organization\Standards\vba. To run the application, keyin one of …

The keyin starts the macro, which immediately calls a locator class. The locator class Implements ILocateCommandEvents. It prompts you to locate a cell.

Once you've located a cell, the macro draws two temporary lines. The first line is drawn from the cell origin to your current cursor location. The second line is drawn from the cell origin to the active view's 'north' (i.e. the view's Y-axis).