Exemplo n.º 1
0
bool IsInSector(Point point, Sector* sector)
{
	Point center_of_arc = GetCenterInArcOfSector(sector);
	float vx = center_of_arc.x - sector->c.c.x;
	float vy = center_of_arc.y - sector->c.c.y;

	float h = sector->r * 0.5f;
	float c = cosf(h);
	float s = sinf(h);
	Point vertex_a = { sector->c.c.x + (vx * c - vy * s), sector->c.c.y + (vy * c + vx * s) };
	Point vertex_b = { sector->c.c.x + (vx * c + vy * s), sector->c.c.y + (vy * c - vx * s) };
	PrintPoint(vertex_a, "black");
	PrintPoint(vertex_b, "black");

	Line line_a = { sector->c.c, vertex_a };
	Line line_b = { sector->c.c, vertex_b };

	float ca = EvaluatePointToLine(point, &line_a);
	float ba = EvaluatePointToLine(vertex_b, &line_a);
	float cb = EvaluatePointToLine(point, &line_b);
	float ab = EvaluatePointToLine(vertex_a, &line_b);

	if (0 <= c)
	{
		if (0 <= ca * ba && 0 <= cb * ab)
			return true;
	}
	else
	{
		if (0 >= ca * ba || 0 >= cb * ab)
			return true;
	}

	return false;
}
Exemplo n.º 2
0
int main(int argc, char **argv) {
    
    struct Point *p;
    
    p = (Point*)malloc(sizeof(Point)); // allocate on the heap
    
    if(p == NULL) {
        std::cerr << "Error allocating memory..\n";
        exit(0);
    }
    
    memset(p, 0, sizeof(Point));
    
    p->x = 100;
    p->y = 200;
    
    PrintPoint(p);
    
    free(p); // free
    
    p = (Point*)calloc(1, sizeof(Point)); // allocate / initalize to zero

    if(p == NULL) {
        std::cerr << "Error allocating memory..\n";
        exit(0);
    }
    
    PrintPoint(p);
    
    free(p); // free
    
    return 0;
}
Exemplo n.º 3
0
void GetEnclosingRectangleOfSector(Sector* sector, Point* down_left, Point* up_right)
{
	Point center_of_arc = GetCenterInArcOfSector(sector);
	float vx = center_of_arc.x - sector->c.c.x;
	float vy = center_of_arc.y - sector->c.c.y;
	float h = sector->r * 0.5f;
	float c = cosf(h);
	float s = sinf(h);
	Point vertex_a = { sector->c.c.x + (vx * c - vy * s), sector->c.c.y + (vy * c + vx * s) };
	Point vertex_b = { sector->c.c.x + (vx * c + vy * s), sector->c.c.y + (vy * c - vx * s) };

	Point up = { sector->c.c.x, sector->c.c.y + sector->c.r };
	Point down = { sector->c.c.x, sector->c.c.y - sector->c.r };
	Point left = { sector->c.c.x - sector->c.r, sector->c.c.y };
	Point right = { sector->c.c.x + sector->c.r, sector->c.c.y };

	up_right->y = IsInSector(up, sector) ? up.y : MAX(MAX(vertex_a.y, vertex_b.y), sector->c.c.y);
	down_left->y = IsInSector(down, sector) ? down.y : MIN(MIN(vertex_a.y, vertex_b.y), sector->c.c.y);
	up_right->x = IsInSector(right, sector) ? right.x : MAX(MAX(vertex_a.x, vertex_b.x), sector->c.c.x);
	down_left->x = IsInSector(left, sector) ? left.x : MIN(MIN(vertex_a.x, vertex_b.x), sector->c.c.x);

	PrintPoint(center_of_arc, "black");
	PrintPoint(sector->c.c, "black");
	PrintPoint(vertex_a, "black");
	PrintPoint(vertex_b, "black");

	PrintPoint(up, IsInSector(up, sector) ? "red" : "yellow");
	PrintPoint(down, IsInSector(down, sector) ? "red" : "yellow");
	PrintPoint(left, IsInSector(left, sector) ? "red" : "yellow");
	PrintPoint(right, IsInSector(right, sector) ? "red" : "yellow");
}
Exemplo n.º 4
0
int main(void)
{
	/*
	Row r;// = {1.1f, 2.2f, 3.3f, 4.4f};
	r[0] = 5.6f;
	std::cout << r[0] << std::endl;
	std::cout << r[1] << std::endl;
	std::cout << r[2] << std::endl;
	std::cout << r[3] << std::endl;
	/**/

	Point p(1.0f, 2.0f, 3.0f);
	Plane pl(Point(0.0f, 0.0f, 0.0f), Vector(1.0f, 1.0f, 0.0f));
	p.Project(pl);
	PrintPoint(p);
	return 0;
}
Exemplo n.º 5
0
/*---------------------------------------------------------------------
ReadVertices: Reads in the vertices, and links them into a circular
list with MakeNullVertex.  There is no need for the # of vertices to be
the first line: the function looks for EOF instead.  Sets the global
variable vertices via the ADD macro.
---------------------------------------------------------------------*/
void	ReadVertices( void )
{
   tVertex  v;
   int      x, y, z;
   int	    vnum = 0;

   while ( scanf ("%d %d %d", &x, &y, &z ) != EOF )  {
      v = MakeNullVertex();
      v->v[X] = x;
      v->v[Y] = y;
      v->v[Z] = z;
      v->vnum = vnum++;
      if ( ( abs(x) > SAFE ) || ( abs(y) > SAFE ) || ( abs(z) > SAFE ) ) {
         printf("Coordinate of vertex below might be too large: run with -d flag\n");
         PrintPoint(v);
      }
   }
}
Exemplo n.º 6
0
int main(){
	int a,b;
	Point P1;
	scanf("%d%d",&a,&b);
	Point P2(a,b);
	scanf("%d%d",&a,&b);
	Point P3(a,b);
	if (P1.IsOrigin()) printf("P1 origin\n");
	else printf("P1 bukan origin\n");
	if (P2.IsOrigin()) printf("P2 origin\n");
	else printf("P2 bukan origin\n");
	if (P3.IsOrigin()) printf("P3 origin\n");
	else printf("P3 bukan origin\n");
	Point P4 = P1.Add(P2,P3);
	Point P5 = P2.Add(P3);
	if (P2.IsEqual(P5)) printf("P2 equal P5\n");
	else printf("P2 not equal P5\n");
	if (P4.IsEqual(P5)) printf("P4 equal P5\n");
	else printf("P4 not equal P5\n");
	scanf("%d%d",&a,&b);
	Point P6 = P2.Add(a,b);
	scanf("%d%d",&a,&b);
	Point P7 = P3.Add(a,b);
	P4.AddToMe(P2);
	scanf("%d%d",&a,&b);
	P5.AddToMe(a,b);
	printf("Kuadran P2 : %d\n",P2.Kuadran());
	printf("Kuadran P3 : %d\n",P3.Kuadran());
	printf("Kuadran P6 : %d\n",P6.Kuadran());
	printf("Kuadran P7 : %d\n",P7.Kuadran());
	printf("P2 : ");
	PrintPoint(P2);
	printf("P3 : ");
	PrintPoint(P3);
	printf("P4 : ");
	PrintPoint(P4);
	printf("P5 : ");
	PrintPoint(P5);
	printf("P6 : ");
	PrintPoint(P6);
	printf("P7 : ");
	PrintPoint(P7);
	return 0;
}