I'm sorry to hear that the function didn't solve the problem. It's about
the best solution I am able of coming up with, and should produce exactly
perpendicular X & Y vectors to within the accuracy of double-precision math.
I added some debug statements to print out all of the variables at full
precision. If you have one that fails, I'd be interested in seeing the
values. * note: the required Cross3D function is not in this post. *
James
Function Add_UCS_improved(origin() As Double, xAxisPnt() _
As Double, yAxisPnt() As Double, ucsName As String) As AcadUCS
' origin, xAxisPnt, and yAxisPnt must all be dimmed (0 to 2)
Dim ucsObj As AcadUCS
Dim xAxisVec(0 To 2) As Double
Dim yAxisVec(0 To 2) As Double
Dim perpYaxisPnt(0 To 2) As Double
Dim xCy As Variant, perpYaxisVec As Variant
debug.print "xAxisPnt: " & xAxisPnt(0) & ", " & xAxisPnt(1) & ", " &
xAxisPnt(2)
debug.print "yAxisPnt: " & yAxisPnt(0) & ", " & yAxisPnt(1) & ", " &
yAxisPnt(2)
debug.print "origin: " & origin(0) & ", " & origin(1) & ", " &
origin(2)
xAxisVec(0) = xAxisPnt(0) - origin(0)
xAxisVec(1) = xAxisPnt(1) - origin(1)
xAxisVec(2) = xAxisPnt(2) - origin(2)
yAxisVec(0) = yAxisPnt(0) - origin(0)
yAxisVec(1) = yAxisPnt(1) - origin(1)
yAxisVec(2) = yAxisPnt(2) - origin(2)
debug.print "xAxis: " & xAxisVec(0) & ", " & xAxisVec(1) & ", " &
xAxisVec(2)
debug.print "yAxis: " & yAxisVec(0) & ", " & yAxisVec(1) & ", " &
yAxisVec(2)
xCy = Cross3D(xAxisVec, yAxisVec)
debug.print "xCy: " & xCy(0) & ", " & xCy(1) & ", " & xCy(2)
perpYaxisVec = Cross3D(xCy, xAxisVec)
debug.print "perpYaxisVec: " & perpYaxisVec(0) & ", " & perpYaxisVec(1)
& ", " & perpYaxisVec(2)
perpYaxisPnt(0) = perpYaxisVec(0) + origin(0)
perpYaxisPnt(1) = perpYaxisVec(1) + origin(1)
perpYaxisPnt(2) = perpYaxisVec(2) + origin(2)
debug.print "perpYaxisPnt: " & perpYaxisPnt(0) & ", " & perpYaxisPnt(1)
& ", " & perpYaxisPnt(2)
Set ucsObj = ThisDrawing.UserCoordinateSystems.Add(origin, xAxisPnt,
perpYaxisPnt, ucsName)
Set Add_UCS_improved = ucsObj
End Function