home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
vis-ftp.cs.umass.edu
/
vis-ftp.cs.umass.edu.tar
/
vis-ftp.cs.umass.edu
/
pub
/
Software
/
ASCENDER
/
ascendMar8.tar
/
UMass
/
BoldtOld
/
MERGE
/
geometry2d.c
next >
Wrap
C/C++ Source or Header
|
1995-04-14
|
2KB
|
106 lines
#include "geometry2d.h"
#include <stdio.h>
#include <math.h>
/*======================================================================\
| GEOMETRY2D.C - 2d point and line geometry |
| |
| 1/28/95 Bob Collins, University of Massachusetts |
\======================================================================*/
/***********/
/* POINT2D */
/***********/
POINT2D *set_point2d(POINT2D *point, float xval, float yval)
{
point->x = xval;
point->y = yval;
return(point);
}
POINT2D *translate_point2d(POINT2D *point, float deltax, float deltay)
{
point->x += deltax;
point->y += deltay;
return(point);
}
POINT2D *copy_point2d(POINT2D *to, POINT2D *from)
{
to->x = from->x;
to->y = from->y;
return(to);
}
void swap_points2d(POINT2D *a, POINT2D *b)
{
POINT2D tmp;
tmp.x = a->x; tmp.y = a->y;
a->x = b->x; a->y = b->y;
b->x = tmp.x; b->y = tmp.y;
return;
}
double distance_pp2d(POINT2D *a, POINT2D *b)
{
double dx,dy;
dx = a->x - b->x;
dy = a->y - b->y;
return(sqrt(dx*dx + dy*dy));
}
/**********/
/* LINE2D */
/**********/
LINE2D *copy_line2d(LINE2D *to, LINE2D *from)
{
to->a = from->a;
to->b = from->b;
to->c = from->c;
return(to);
}
LINE2D *set_line2d(LINE2D *line, float aval, float bval, float cval)
{
float tmp;
tmp = sqrt(aval*aval + bval*bval);
if (tmp == 0.0)
return(NULL);
else {
line->a = aval/tmp;
line->b = bval/tmp;
line->c = cval/tmp;
return(line);
}
}
LINE2D *set_line2d_from_endpoints(LINE2D *line, POINT2D *pt1, POINT2D *pt2)
{
return(set_line2d(line, pt1->y - pt2->y, pt2->x - pt1->x,
pt1->x * pt2->y - pt2->x * pt1->y));
}
float distance_pl2d(POINT2D *point, LINE2D *line)
{
return(fabs(line->a * point->x + line->b * point->y + line->c));
}
float signed_distance_pl2d(POINT2D *point, LINE2D *line)
{
return(line->a * point->x + line->b * point->y + line->c);
}
float sin_angle_ll2d(LINE2D *line1, LINE2D *line2)
{
return(fabs((line1->a * line2->b) - (line1->b * line2->a)));
}