Spherical Coordinates

My goal is to draw on the sphere converting latitude longitude coordinates to xyz values. Once coordinates are calculated, every line on a sphere is an arc. To draw an arc with known endpoints, known radius and known center, you would think would be simple, but consider what if the points are inaccurate and an arc cannot be drawn. That is why the AddArc method requires a Center, a Radius, a Start Angle and an End Angle. It calculates the points. But notice, there is no opportunity to tilt the arc up into 3D space. It will lie in the XY plane. To draw an arc on a sphere from a center, a radius and two known points, a user coordinate system must be created containing the 3 points, and the angle between points has to be calculated. A UCS point set requires three points that form a right angle. the origin, one of the endpoints, and a normal point. There might be another problem – methods from VBA (ActiveX) generally ignore user coordinate systems and work only in World coordinate system, Autocad’s base of operation. However the help for addarc mentions the center is in WCS, but not the angles. I assume the angles are calculated from UCS. (update a few days later – they are not). Then the angle between points would be calculated from the X axis of the user coordinate system. I have not tried it yet.

Generally if an ActiveX method requires a point, its a WCS point. AddLine is a fully functional 3D command. It takes two 3D points as input. It does not matter what UCS is current. It ignores it. If VBA has the point 0,0,0 as the first point of a line, it starts the line at WCS 0,0,0 no matter where the origin is for the current UCS. That is not so at the command line, 0,0,0 typed at the command line to the line prompt is interpreted to be the origin of the current UCS.

Circle is a little different. you can draw circles at different Z elevations without changing the UCS from the command line, because the center can be any 3D point. You can do the same from VBA, but subsequent prompts and input do not allow you to tip the circle so that it is not parallel to the current UCS.

we need to survey our basic tools and see how they act and what they require.

we need some ucs tools and some viewpoint tools. viewpoint is somewhat more involved than ucs. it has more variables and finally whatever view is created has to be applied to the current viewport. for now i am going to rely on some simple macros and my 3Dconnexion mouse, which works great, the simple one.

The old viewpoint command, before the dialog box, just took a direction vector. such as “1,-1,1” for a southeast viepoint. We can throw that into a program quick if we need it. mostly i will probably rely on the mouse. but here is the macro sub using sendcommand. if you type VP at the command line and get the dialog, type -VP. if that doesnt work look at your pgp which is re-directing. this code works if -vp works at your command line.

Sub vp(str_vp As String)
Dim str As String
'these are commented out for reference 
'acadDoc.SendCommand "-vp" & vbCr & "-1,-1,1" & vbCr  'SW
'acadDoc.SendCommand "-vp" & vbCr & "1,-1,1" & vbCr  'SE
'acadDoc.SendCommand "-vp" & vbCr & "1,1,1" & vbCr  'NE
'acadDoc.SendCommand "-vp" & vbCr & "-1,1,1" & vbCr  'NW
'acadDoc.SendCommand "-vp" & vbCr & "0,0,1" & vbCr  'TOP
'acadDoc.SendCommand "-vp" & vbCr & "0,0,-1" & vbCr  'BOTTOM
'acadDoc.SendCommand "-vp" & vbCr & "-1,0,0" & vbCr  'LEFT
'acadDoc.SendCommand "-vp" & vbCr & "1,0,0" & vbCr  'RIGHT
'acadDoc.SendCommand "-vp" & vbCr & "0,-1,0" & vbCr  'FRONT
'acadDoc.SendCommand "-vp" & vbCr & "0,1,0" & vbCr  'BACK

 Select Case UCase(str_vp)
    Case "TOP"
    str = "0,0,1"
    Case "FRONT"
    str = "0,-1,0"
    Case "RIGHT"
    str = "1,0,0"
    Case "LEFT"
    str = "-1,0,0"
    Case "BACK"
    str = "0,1,0"
    Case "TOP_FRONT"
    str = "0,-1,1"
    Case "SW"
    str = "-1,-1,1"
    Case "SE"
    str = "1,-1,1"
    Case "NE"
    str = "1,1,1"
    Case "NW"
    str = "-1,1,1"
    Case "BOTTOM"
    str = "0,0,-1"
    Case Else
    Exit Sub
  End Select
acadDoc.SendCommand "-vp" & vbCr & str & vbCr
End Sub

next we need to survey our basic tools, line, circle, arc, polyline, and ucs with regard to how they work in 3D space. we will need some text labels, we will want to dimension in 3D. we can download the formulas to convert from latitude longitude to cartesian but we want to show how they are developed. The diameter of the earth is not constant. People who map for a living know exactly what the bulge is. we are going to assume a perfect sphere, but we will use a variable for the Radius so results will be general for a bowling ball or the earth.

once we have the autocad tools, we should be able to download some coordinates into excel and draw arcs between them from vba. assuming i can draw 3D arcs.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.