ftp.nice.ch/pub/next/science/cartography/ICAO.0.7b.s.tar.gz#/ICAOfNEXT.0.7b/soaring.c

This is soaring.c in view mode; [Download] [Up]

/****************************************************************
 *                                                              *
 *                        I C A O   M a p  -                    *
 *                                                              *
 *             A n   A v i a t i o n   U t i l i t y            *
 *                                                              *
 *                                                              *
 *            Copyright (C) 1993, 1994  Martin Pauly            *
 *                                                              *
 *                   N e x t   V e r s i o n                    *
 *                                                              *
 *       Copyright (C) 1994  Stefan Leuker & Oliver Meyer       *
 *                                                              *
 *   This file may be freely distributed only if it includes    *
 *                the above copyright notice.                   *
 *                                                              *
 ****************************************************************/

#import "soaring.h"


char              **routearray;
char                str_km[20];

OBJECT             *turn1[MAXROUTES];	/* store suggested routes here */
OBJECT             *turn2[MAXROUTES];

OBJECT             *selected1, *selected2;	/* waypoints of selected route */

int                 numberofroutes = 0;


/* trim name to 30 chars */

char               *
trim(char *string)
{
	static char         temp[256];
	int                 i;

	strcpy(temp, string);
	temp[30] = 0;

	while (strlen(temp) < 30)
		strcat(temp, " ");

	for (i = 0; i < strlen(temp); i++)
		if (temp[i] == '_')
			temp[i] = ' ';

	return temp;
}



/* check if triangle conforms to FAI rules */

int 
isFAITriangle(LOCATION a, LOCATION b, LOCATION c)
{
	double              totaldist, dist1, dist2, dist3, minside, maxside;
	int                 ok;

	ok = 1;
	dist1 = distance(a, b);
	dist2 = distance(b, c);
	dist3 = distance(c, a);

	totaldist = dist1 + dist2 + dist3;

	if (totaldist >= 500 / 1.852)
		minside = totaldist * 0.25;
	else
		minside = totaldist * 0.28;
	maxside = totaldist * 0.45;

	if ((dist1 < minside) || (dist2 < minside) || (dist3 < minside))
		ok = 0;

	if ((dist1 > maxside) || (dist2 > maxside) || (dist3 > maxside))
		ok = 0;

	return ok;
}



/* get object name and description string */

char               *
makedesc(OBJECT * object)
{
	static char         temp[256];
	int                 i;

	if (object->type != O_WAYPOINT)
		sprintf(temp, "%s (%s)", object->name,
						objecttypestring(object->type));
	else
	if (object->alias)
		sprintf(temp, "%s %s", object->name, object->alias);
	else
		sprintf(temp, "%s", object->name);

	for (i = 0; i < strlen(temp); i++)
		if (temp[i] == '_')
			temp[i] = ' ';

	return temp;
}


/* suggest triangle */

void 
suggest(int distkm)
{
	int                 i, j, numberofturns;
	OBJECT             *turns[1000];	/* possible waypoints */
	double              mindist, maxdist, minside, maxside;
	double              totaldistance, tempdist;


	totaldistance = distkm / 1.852;	/* NM */


	if (currentroute[FROM] && totaldistance)	/* don't try if no start point
																			 * specified */
	{

		numberofturns = 0;

	/*
	 * FAI triangle: each side must be at least 28% of the total distance, no
	 * side may be longer then 45% of the total distance: 
	 */

		mindist = totaldistance;
		maxdist = totaldistance + 8;			/* 8 NM tolerance */

		minside = mindist * 0.28;
		maxside = maxdist * 0.45;
		if (maxdist > 500 / 1.852)	/* 500+ km: shortest side only needs to be 25
																 * % */
			minside = mindist * 0.25;

		for (i = 0; i < db_objects; i++)
		{
			tempdist = distance(currentroute[FROM]->location, objectlist[i]->location);
			if ((tempdist >= minside) && (tempdist <= maxside))
				if (((objectlist[i]->type < O_VOR) ||
						 (objectlist[i]->type == O_WAYPOINT) ||
						 (objectlist[i]->type == O_LAKE)) &&
						(objectlist[i]->name) && ((*objectlist[i]).name[0]))
				{
					turns[numberofturns] = objectlist[i];
					if (numberofturns < 1000)
						numberofturns++;
				}
		}

	/* check possible triangles */

		numberofroutes = 0;

		for (i = 0; i < numberofturns - 1; i++)
		{
			for (j = i + 1; j < numberofturns; j++)
			{
				tempdist = distance(currentroute[FROM]->location, turns[i]->location) +
					distance(turns[i]->location, turns[j]->location) +
					distance(turns[j]->location, currentroute[FROM]->location);

				if ((tempdist >= mindist) && (tempdist <= maxdist))
					if (isFAITriangle(currentroute[FROM]->location, turns[i]->location,
														turns[j]->location))
					{
						turn1[numberofroutes] = turns[i];
						turn2[numberofroutes] = turns[j];
						if (numberofroutes < MAXROUTES)
							numberofroutes++;
					}
			}
		}

	/* evaluate ease of route, sort accordingly */

	/* (still to be done...) */

	}
}

These are the contents of the former NiCE NeXT User Group NeXTSTEP/OpenStep software archive, currently hosted by Netfuture.ch.