Karoshi MSX Community
05 de Julio de 2021, 01:17:42 pm *
Bienvenido(a), Visitante. Por favor, ingresa o regístrate.

Ingresar con nombre de usuario, contraseña y duración de la sesión
Noticias:
 
   Inicio   Ayuda Buscar Ingresar Registrarse  
Páginas: [1]
  Imprimir  
Autor Tema: Approximate Distance between two points.  (Leído 3846 veces)
0 Usuarios y 1 Visitante están viendo este tema.
ARTRAG
Visitante
« : 22 de Mayo de 2008, 01:52:19 pm »

Código:
/*
 * Approximate Distance between two points.
 *
 * When either the X or Y component dwarfs the other component,
 * this function is almost perfect, and otherwise, it tends to
 * over-estimate about one grid per fifteen grids of distance.
 *
 * Algorithm: hypot(dy,dx) = max(dy,dx) + min(dy,dx) / 2
 */
int distance(int y1, int x1, int y2, int x2)
{
int dy, dx, d;


/* Find the absolute y/x distance components */
dy = (y1 > y2) ? (y1 - y2) : (y2 - y1);
dx = (x1 > x2) ? (x1 - x2) : (x2 - x1);

/* Hack -- approximate the distance */
d = (dy > dx) ? (dy + (dx >> 1)) : (dx + (dy >> 1));

/* Return the distance */
return (d);
}
En línea
Páginas: [1]
  Imprimir  
 
Ir a:  

Impulsado por MySQL Impulsado por PHP Powered by SMF 1.1.21 | SMF © 2013, Simple Machines XHTML 1.0 válido! CSS válido!