[V8i VBA] Automating rotated cell insertion - which Matrix3d method?

In an existing macro, I can supply a list of cartesian coordinates from a CSV file, select a target element and for each coordinate, calculate the bearing rotation (angle measured clockwise between north to line perpendicular from coordinate to target element) and write it to the next column in the CSV.

In my current macro I want to be able to place cells at the same coordinates using the calculated angles however I am unsure which Matrix3D method I should use and looking for some advice.

  • Function ConstructMatrix3D (ByVal degrees As Double) As Matrix3D
      Dim angle As Double
      angle = Radians (degrees)
      ' Your angle is measured from North, so you may need to subtract 90 degrees if cell is oriented along X axis
      angle = angle - Pi()
      Const Z As Long = 2
      ConstructMatrix3D = Matrix3dFromAxisAndRotationAngle (Z, angle)
    End Function

     
    Regards, Jon Summers
    LA Solutions

    Answer Verified By: Barry Lothian 

  • Hi Jon, many thanks for the snippet.

    I was testing the Matrix3dFromAxisAndRotationAngle method prior to your reply but found I was getting the wrong rotation.

    I gave your function a test with the angle = angle - Pi() line commented and uncommented but found the cell rotations to not be correct.

    The comment in your function did however lead me to the correct solution in the end which is below:

    Function ConstructMatrix3D(ByVal degrees As Double) As Matrix3d
    Dim angle                                         As Double
        angle = Radians(degrees)
        angle = (2 * Pi) - angle
        Const Z                                       As Long = 2
        ConstructMatrix3D = Matrix3dFromAxisAndRotationAngle(Z, angle)
    End Function

    I've verified your reply as ultimately it does do what was initially asking, thanks once again.