how to find a lat/log at a given distance from a given lat/log
-
I have a problem . I have to draw a circle at a particular distance say 50 meters from a given lat/log.I refered to Aviation formula's and find a formula to calculate lat/log at a distance and at a bearing which is as follows:- A point {lat,lon} is a distance d out on the tc radial from point 1 if: lat=asin(sin(lat1)*cos(d)+cos(lat1)*sin(d)*cos (tc)) IF (cos(lat)=0) lon=lon1 // endpoint a pole ELSE lon=mod(lon1-asin(sin(tc)*sin(d)/cos (lat))+pi,2*pi)-pi ENDIF This algorithm is limited to distances such that dlon <pi/2, i.e those that extend around less than one quarter of the circumference of the earth in longitude. A completely general, but more complicated algorithm is necessary if greater distances are allowed: lat =asin(sin(lat1)*cos(d)+cos(lat1)*sin(d)*cos(tc)) dlon=atan2(sin(tc)*sin(d)*cos(lat1),cos(d)-sin (lat1)*sin(lat)) lon=mod( lon1-dlon +pi,2*pi )-pi for this i have written this coding:- Private Sub cmdNextPoint_Click() Dim lat2 As Double, lon2 As Double, theta As Double, d As Double,Aasin As Double,Aatan2 As Double Pi = 3.14159265358979 d = 50 theta = 90 * 0.0174532925 txtLatitude.Text = 22.51791 txtLongitude.Text = 87.46598 Aasin = Sin(Val(txtLatitude.Text)) * Cos(d) + Cos(Val(txtLatitude.Text)) * Sin(d) * Cos(theta) lat2 = atan2(Aasin, Sqr(1 - Aasin * Aasin)) Aatan2 = Sin(theta) * Sin(d) * Cos(Val(txtLatitude.Text)) Batan2 = Cos(d) - Sin(Val(txtLatitude.Text)) * Sin(lat2) lon2 = ((Val(txtLongitude.Text) - atan2(Aatan2, Batan2) + Pi) Mod (2 * Pi)) - Pi txtLatitude2.Text = lat2 txtLongitude2.Text = lon2 End Sub Public Function atan2(ByVal y As Double, ByVal x As Double) As Double If y > 0 Then If x >= y Then atan2 = Atn(y / x) ElseIf x <= -y Then atan2 = Atn(y / x) + Pi Else atan2 = Pi / 2 - Atn(x / y) End If Else If x >= -y Then atan2 = Atn(y / x) ElseIf x <= y Then atan2 = Atn(y / x) - Pi Else atan2 = -Atn(x / y) - Pi / 2 End If End If End Function in this i m finding a point which is at a distance of 50 meters from the latitude 22.51791 and longitude 87.46598 and at a bearing of 90 degrees.Somebody told me that to draw a circle i have to find out 360 points then by using the DrawPolygon method the circle can be drawn.So firstly i m finding one point.It is not giving me the desired result that should be latitude = 22.51841 and longitude = 87.46598.Can anybody help me .Just tell me where i m wrong.I m using the mapwingis activex control to displ
-
I have a problem . I have to draw a circle at a particular distance say 50 meters from a given lat/log.I refered to Aviation formula's and find a formula to calculate lat/log at a distance and at a bearing which is as follows:- A point {lat,lon} is a distance d out on the tc radial from point 1 if: lat=asin(sin(lat1)*cos(d)+cos(lat1)*sin(d)*cos (tc)) IF (cos(lat)=0) lon=lon1 // endpoint a pole ELSE lon=mod(lon1-asin(sin(tc)*sin(d)/cos (lat))+pi,2*pi)-pi ENDIF This algorithm is limited to distances such that dlon <pi/2, i.e those that extend around less than one quarter of the circumference of the earth in longitude. A completely general, but more complicated algorithm is necessary if greater distances are allowed: lat =asin(sin(lat1)*cos(d)+cos(lat1)*sin(d)*cos(tc)) dlon=atan2(sin(tc)*sin(d)*cos(lat1),cos(d)-sin (lat1)*sin(lat)) lon=mod( lon1-dlon +pi,2*pi )-pi for this i have written this coding:- Private Sub cmdNextPoint_Click() Dim lat2 As Double, lon2 As Double, theta As Double, d As Double,Aasin As Double,Aatan2 As Double Pi = 3.14159265358979 d = 50 theta = 90 * 0.0174532925 txtLatitude.Text = 22.51791 txtLongitude.Text = 87.46598 Aasin = Sin(Val(txtLatitude.Text)) * Cos(d) + Cos(Val(txtLatitude.Text)) * Sin(d) * Cos(theta) lat2 = atan2(Aasin, Sqr(1 - Aasin * Aasin)) Aatan2 = Sin(theta) * Sin(d) * Cos(Val(txtLatitude.Text)) Batan2 = Cos(d) - Sin(Val(txtLatitude.Text)) * Sin(lat2) lon2 = ((Val(txtLongitude.Text) - atan2(Aatan2, Batan2) + Pi) Mod (2 * Pi)) - Pi txtLatitude2.Text = lat2 txtLongitude2.Text = lon2 End Sub Public Function atan2(ByVal y As Double, ByVal x As Double) As Double If y > 0 Then If x >= y Then atan2 = Atn(y / x) ElseIf x <= -y Then atan2 = Atn(y / x) + Pi Else atan2 = Pi / 2 - Atn(x / y) End If Else If x >= -y Then atan2 = Atn(y / x) ElseIf x <= y Then atan2 = Atn(y / x) - Pi Else atan2 = -Atn(x / y) - Pi / 2 End If End If End Function in this i m finding a point which is at a distance of 50 meters from the latitude 22.51791 and longitude 87.46598 and at a bearing of 90 degrees.Somebody told me that to draw a circle i have to find out 360 points then by using the DrawPolygon method the circle can be drawn.So firstly i m finding one point.It is not giving me the desired result that should be latitude = 22.51841 and longitude = 87.46598.Can anybody help me .Just tell me where i m wrong.I m using the mapwingis activex control to displ
Hi, I did not look into your code or formulas as they are pretty unreadable; you should enclose the lot with PRE tags. If you get trig functions completely wrong, the most likely cause is you forgot in most languages and math packages the angular units are radians, not degrees. So you need a factor, say in C#:
double ToRadians=Math.PI/180;
or something similar in VB.NET PS: Notice the effect of PRE tags? :)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read code that is properly formatted, adding PRE tags is the easiest way to obtain that.
-
I have a problem . I have to draw a circle at a particular distance say 50 meters from a given lat/log.I refered to Aviation formula's and find a formula to calculate lat/log at a distance and at a bearing which is as follows:- A point {lat,lon} is a distance d out on the tc radial from point 1 if: lat=asin(sin(lat1)*cos(d)+cos(lat1)*sin(d)*cos (tc)) IF (cos(lat)=0) lon=lon1 // endpoint a pole ELSE lon=mod(lon1-asin(sin(tc)*sin(d)/cos (lat))+pi,2*pi)-pi ENDIF This algorithm is limited to distances such that dlon <pi/2, i.e those that extend around less than one quarter of the circumference of the earth in longitude. A completely general, but more complicated algorithm is necessary if greater distances are allowed: lat =asin(sin(lat1)*cos(d)+cos(lat1)*sin(d)*cos(tc)) dlon=atan2(sin(tc)*sin(d)*cos(lat1),cos(d)-sin (lat1)*sin(lat)) lon=mod( lon1-dlon +pi,2*pi )-pi for this i have written this coding:- Private Sub cmdNextPoint_Click() Dim lat2 As Double, lon2 As Double, theta As Double, d As Double,Aasin As Double,Aatan2 As Double Pi = 3.14159265358979 d = 50 theta = 90 * 0.0174532925 txtLatitude.Text = 22.51791 txtLongitude.Text = 87.46598 Aasin = Sin(Val(txtLatitude.Text)) * Cos(d) + Cos(Val(txtLatitude.Text)) * Sin(d) * Cos(theta) lat2 = atan2(Aasin, Sqr(1 - Aasin * Aasin)) Aatan2 = Sin(theta) * Sin(d) * Cos(Val(txtLatitude.Text)) Batan2 = Cos(d) - Sin(Val(txtLatitude.Text)) * Sin(lat2) lon2 = ((Val(txtLongitude.Text) - atan2(Aatan2, Batan2) + Pi) Mod (2 * Pi)) - Pi txtLatitude2.Text = lat2 txtLongitude2.Text = lon2 End Sub Public Function atan2(ByVal y As Double, ByVal x As Double) As Double If y > 0 Then If x >= y Then atan2 = Atn(y / x) ElseIf x <= -y Then atan2 = Atn(y / x) + Pi Else atan2 = Pi / 2 - Atn(x / y) End If Else If x >= -y Then atan2 = Atn(y / x) ElseIf x <= y Then atan2 = Atn(y / x) - Pi Else atan2 = -Atn(x / y) - Pi / 2 End If End If End Function in this i m finding a point which is at a distance of 50 meters from the latitude 22.51791 and longitude 87.46598 and at a bearing of 90 degrees.Somebody told me that to draw a circle i have to find out 360 points then by using the DrawPolygon method the circle can be drawn.So firstly i m finding one point.It is not giving me the desired result that should be latitude = 22.51841 and longitude = 87.46598.Can anybody help me .Just tell me where i m wrong.I m using the mapwingis activex control to displ
I'm no expert on the math, but it appears that not all the values you are passing to the Trig functions are expressed in Radians. It appears that you're using Radians in some calls, but Degrees in others. This will definately give you bad results.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007, 2008
But no longer in 2009...