thanks, it seems to have pretty much the same formulas as i used, a couple differences.
but in the end my function is going to be within Access/VB so that it can calculate the bearing without MapInfo. my problem there is that VB doesn't have native derived math functions, and i'm not smart enough to figure them out for myself. essentially if i knew how to to the ASIN function in Access I think everything would be peachy. ash -----Original Message----- From: RandaEnt. [mailto:[EMAIL PROTECTED]] Sent: Friday, 2 August 2002 1:54 PM To: Simmonds, Ashley (PTB) Subject: Re: MI-L Calculate Compass Heading Ash: Here is a program called bearing.mb If you are a MapBasic user, compile it, it's pretty handy. There are portions of the code that should answer your question?????? Here goes: ' ************ ' BEARING.MB ' ************ ' MapBasic program that demonstrates how to determine the compass ' bearing and distance of a line drawn on a mapper window. ' The bearing angle is in degrees, from 0-360, where zero is facing true north. ' By Sean Reese <[EMAIL PROTECTED]> ' Copyright � 1997, GeoTrek Corp. ' ' This application is made available for the personal and nonprofit use ' of MapInfo users. It may not be used for commercial purposes without ' written permission from the author. Include "mapbasic.def" Include "icons.def" Declare Sub Main Declare Sub ShowBearing Declare Sub ShutDown Declare Sub About Sub Main OnError GoTo Crash ' Create custom ToolButtons. The user selects the Draw Line tool, ' then draws a line object on the map. Then the ShowBearing procedure ' will display the line extents, length and compass bearing. ' Also creates an About button and a program Exit button. ' Create ButtonPad "Bearing" As ToolButton Icon 185 HelpMsg "Draw a bearing line on the map. Dialog displays compass bearing, distance and extents.\nDraw Bearing Line" Cursor MI_CURSOR_CROSSHAIR ' the draw-mode mouse cursor DrawMode DM_CUSTOM_LINE ' let the user click, but not drag Calling ShowBearing PushButton Icon 195 HelpMsg "About the Bearing.MB program\nAbout Bearing.MB" Calling About PushButton Icon 275 HelpMsg "End Program\nEnd Program" Calling ShutDown Width 3 Position (2,2) Show 'Error Handler Exit Sub Crash: Note "Error Initializing Bearing.MBX" End Program End Sub ' When the user selects the custom tool and draws a line on a window, ' the program then calls the ShowBearing procedure. ' Displays a dialog box with the line extents, length and compass bearing. ' Sub ShowBearing OnError GoTo Crash Dim f_length As Float ' Line length Dim f_angle As Float ' Line angle Dim x_1, y_1, x_2, y_2, Dy As Float Dim win_id As Integer ' First, make sure the user didn't click in a Layout window. win_id = FrontWindow() If WindowInfo(win_id, WIN_INFO_TYPE) <> WIN_MAPPER Then Note "This tool may only be used on a Map window." Exit Sub End If ' Retrieve the beginning and end coordinates of the line the user created x_1 = CommandInfo(CMD_INFO_X) y_1 = CommandInfo(CMD_INFO_Y) x_2 = CommandInfo(CMD_INFO_X2) y_2 = CommandInfo(CMD_INFO_Y2) 'Calculate length of drawn line f_length = Distance(x_1,y_1,x_2,y_2,"mi") If f_length = 0 Then Exit Sub End If 'Calculate change in Y Dy = Distance(x_2,y_2,x_2,y_1,"mi") 'Calculate angle, with zero degrees being east-west. Uses if/then for 'horizontal and vertical lines because of an apparent MapInfo bug that 'occasionally causes error when taking Asin(1). If Dy/f_length = 0 Then 'Horizontal line f_angle = 0 Elseif Dy/f_length = 1 Then 'Vertical line f_angle = 90 Else f_angle = Asin(Dy/f_length)* RAD_2_DEG End If 'Now calculates bearing (angle), with zero degrees being True North. 'Uses the standard 360-degree compass rose. If x_2 >= x_1 AND y_2 > y_1 Then f_angle = Abs(f_angle - 90) Elseif x_2 > x_1 AND y_2 <= y_1 Then f_angle = Abs(f_angle + 90) Elseif x_2 <= x_1 AND y_2 < y_1 Then f_angle = Abs(f_angle - 90) + 180 Elseif x_2 < x_1 AND y_2 >= y_1 Then f_angle = Abs(f_angle + 270) End If ' Insert the line object into the map's Cosmetic layer Insert Into WindowInfo(win_id, WIN_INFO_TABLE) (Object) Values(CreateLine(x_1,y_1,x_2,y_2)) Dialog Title "Line Info" Control StaticText Title "Beginning X1" Position 10, 10 Control StaticText Title Format$(x_1, "##########.##########") Position 55, 10 Control StaticText Title "Beginning Y1" Position 10, 20 Control StaticText Title Format$(y_1, "##########.##########") Position 55, 20 Control StaticText Title "Ending X2" Position 10, 35 Control StaticText Title Format$(x_2, "##########.##########") Position 55, 35 Control StaticText Title "Ending Y2" Position 10, 45 Control StaticText Title Format$(y_2, "##########.##########") Position 55, 45 Control StaticText Title "Bearing" Position 10, 65 Control StaticText Title Format$(f_angle, "##0.#####") Position 42, 65 Control StaticText Title "degrees (true north)" Position 78, 65 Control StaticText Title "Length" Position 10, 77 Control StaticText Title Format$(f_length, "#######.#####") Position 42, 77 Control StaticText Title "miles" position 78, 77 Control GroupBox position 5,57 width 142 height 33 Control StaticText Title "" position 5,91 Control OKButton 'Error Handler Exit Sub Crash: Resume Next End Sub ' The Aboutcontrol gro sub displays an About dialog box. ' Called when the user clicks the About button. Sub About Dialog Title "About the Bearing utility..." Control StaticText Title "This MapBasic application lets you draw a line" Position 10, 10 Control StaticText Title "on a map's cosmetic layer, then calculates the line's" Position 10, 20 Control StaticText Title "distance and compass bearing." Position 10, 30 Control StaticText Title "" Position 10, 45 Control StaticText Title "By Sean Reese" Position 10, 55 Control StaticText Title "[EMAIL PROTECTED]" Position 10, 65 Control StaticText Title "Copyright � 1997, GeoTrek Corp." Position 10, 75 Control OKButton Title "OK" End Sub ' The ShutDown sub removes this application from memory, ' along with its custom buttons. Sub ShutDown End Program End Sub ----- Original Message ----- From: "Simmonds, Ashley (PTB)" <[EMAIL PROTECTED]> To: "'Mapinfo List (E-mail)'" <[EMAIL PROTECTED]> Sent: Thursday, August 01, 2002 6:22 PM Subject: MI-L Calculate Compass Heading > helloo, > > ONLY READ FURTHER IF YOU ARE ALREADY BORED, I TAKE NO RESPONSIBILITY FOR > INDUCED SOMNAMBULISM. > > can anyone tell me how stupid i am? this isn't a necessary function of my > program, just a nice add-on, but can anyone tell me if my calculations are > correct or not. > > given a start X / Y and an end X / Y i want to calculate a bearing. please > bear with me, i am in the southern hemisphere so this may be backwards for > many of you. > > > > ' Centre of Adelaide, the city that always sleeps > StartX = 138.6 > StartY = -34.9288 > > ' my girlfriends place > EndX = 138.59143 > EndY = -34.909724 > > 'the number of metres in a degrees of longitude/latitude in the general > Adelaide area, good enough for small calculations on a flat-earth model > Xpants = 91163.74274 > Ypants = 111198.3871 > > 'DISTANCE between Start and End > Square Root of > ((( StartX - EndX ) * Xpants ) ^ 2 ) > + > ((( StartY - EndY ) * Ypants ) ^ 2 ) > > DISTANCE = 2260 metres > > > 'RADIANS from start to end > ASIN of > ((( EndY - StartY ) * Ypants ) / DISTANCE ) > > RADIANS = 1.2179 > > > 'convert to DEGREES > RADIANS * 180 / Pi > > DEGREES = 69.78 > > > 'then werk out the final answer > if StartX < EndX then 'if start point is west of end point > > 90 - DEGREES = 20.219 > > elseif StartX > EndX then 'if start point is east of end point > > 360 - ( 90 - DEGREES ) = 339.78 > > end if > > > > in this case the start point is east of the end point, so the final answer > is 339.78 degrees, which when looked at on a map, seems correct. > > if there is an easier way to do this then please let me know, but now i'm > trying to make a function in VBA which does all this, and i hit a wall when > it comes to the ASIN function, a derived function which is defined in Excel > but not in Access. > > so does anyone know how to do the arcsine calculation in Access/VB? it's > probably really easy, but i'm no trig guru, i really struggled to get this > far. > > gramercy > > ash > > ---------------------------------------------------------------------------- ---- > --------------------------------------------------------------------- > List hosting provided by Directions Magazine | www.directionsmag.com | > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > Message number: 2329
--------------------------------------------------------------------- List hosting provided by Directions Magazine | www.directionsmag.com | To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] Message number: 2332
