|
#include <stdio.h>
typedef struct { double x, y; } Point;
double line(Point *a, Point *b, Point *c)
{
return (a->y - b->y)*(c->x - b->x) - (a->x - b->x)*(c->y - b->y);
}
int is_inside(Point *a, Point *b, Point *c, Point *p)
{
return line(a, b, c) * line(a, b, p) > 0
&& line(b, c, a) * line(b, c, p) > 0
&& line(c, a, b) * line(c, a, p) > 0;
}
int main(void)
{
Point a = {0, 0}, b = {4, 0}, c = {3, 3}, p;
for (p.x = -1; p.x <= 5; p.x++)
for (p.y = -1; p.y <= 4; p.y++)
printf("(%2g,%2g) %s\n", p.x, p.y,
is_inside(&a, &b, &c, &p) ? "in" : "out");
return 0;
}
|