Sign in to follow this  
Guest

Runways

Recommended Posts

Hi all,I'm presently working on the logbook add-in for Fly! II and am struggling with a problem. I want to record the runway that is used when taking off (just in case a runway is actually used!). However, I don't see in the SDK where I can easily determine this information. Does anyone have experience with this bit of the SDK?Cheers, Tony

Share this post


Link to post
Share on other sites
Help AVSIM continue to serve you!
Please donate today!

Sure don't sorry. But I like your idea! I would really like to have something like that. Good luck with it.

Share this post


Link to post
Share on other sites

For anyone who is curious...I figured out a way to determine whether or not a plane is on a runway. Using some formulae for a general triangle, proceed as follows:The distance between two points (using lat and lon as rough approximations of x and y) is sqrt( power( p1.lat - p2.lat, 2 ) + power( p1.lon - p2.lon, 2 ) )Using the runway ends and the position of the aircraft, we have a triangle (we'll worry about the aircraft being on the centerline of the runway in a minute). So, ...The distance between the base runway end and the aircraft is a.The distance between the reciprocal runway end and the aircraft is b.And the distance between the two runway ends is c.Using Heron's formula, we can find the exact (perpendicular) distance from the centerline of the runway as...

[b][i]	2h = -  * sqrt( s * ( s - a ) * ( s - b ) * ( s - c ) )	c[/i][/b]

where

[b][i]	1s = - ( a + b + c )	2[/i][/b]

If h is less than or equal to half the width of the runway, then the plane is directly over that runway. Now, if the plane is exactly on the center line, h = 0 (as it should) because the last term of h, i.e., ( s - c ) will be 0 because s will be equal to c. So even when the triangle is a straight line, the formula gives the correct result. Anyway, happy head scratching...Cheers, Tony

Share this post


Link to post
Share on other sites

Hi Tony,Out-standing.......I'm sure this formulu can be used by many developers.Good LuckJohn

Share this post


Link to post
Share on other sites

Addendum:In the formulae that I gave for determining whether or not an aircraft is on a given runway, I forgot to put in a crucial step...Since we are calculating distance using lon/lat for x/y, the distance computed is actually a measure of arcseconds. This turns out to be not entirely useful. What us needed is a conversion from arcseconds to feet, so that comparison to the runway width is meaningful. As such, the following code snippet gets the job done correctly:

double distance( SPosition a, SPosition b ){	return sqrt( ( ( a.lat - b.lat ) * ( a.lat - b.lat ) ) + ( ( a.lon - b.lon ) * ( a.lon - b.lon ) ) );}bool oncourse( float rmh, float umh ){	float rmhl = rmh - 10.0;	float rmhh = rmh + 10.0;	if( rmhl <= umh && umh <= rmhh )		return true;	if( rmhl < 0.0 )	{		rmhl += 360.0;		rmhh += 360.0;		if( rmhl <= umh && umh <= rmhh )			return true;	}	else if( rmhh > 360.0 )	{		rmhl -= 360.0;		rmhh -= 360.0;		if( rmhl <= umh && umh <= rmhh )			return true;	}	return false;}bool heron( SPosition a, SPosition b, SPosition c, float scale, double rw2 ){	double da = distance( b, c );	double db = distance( a, c );	double dc = distance( a, b );	double tscale = scale / dc;	da *= tscale;	db *= tscale;	dc = scale;	double s = ( da + db + dc ) / (double) 2.0;	double hc = 2 * sqrt( s * ( s - da ) * ( s - db ) * ( s - dc ) ) / dc;	return hc <= rw2;}void computeRunway( SAirport *airport, SFlyObjectRef *user ){	SRunway *p = airport->runways;	SPosition c;	float umh;	APIGetObjectPosition( user, &c );	APIGetObjectMagneticHeading( user, &umh );	while( p )	{		if( heron( p->base.pos, p->recip.pos, c, p->length, (float) p->width / (float) 2.0 ) )		{			//found it!			if( oncourse( p->base.magneticHeading, umh ) )			{				strcpy( m_runway, p->base.id );				return;			}			if( oncourse( p->recip.magneticHeading, umh ) )			{				strcpy( m_runway, p->recip.id );				return;			}		}		p = p->next;	}	m_runway&l;0&r; = 0;}

Simply call computeRunway() passing the airport and aircraft in question, and a global string m_runway will be filled with either a runway or a null string.Cheers, Tony

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this