Check if a point is inside of a Triangle

/*In this program you will give 4 coordinates, 3 that will form the triangle and it will check if the fourth is inside or out the triangle*/

#include<stdio.h>
#include<conio.h>

    struct point{ int x,y;};
    int main()
    {
     point a, b, c,d;
    int i;
    printf("First coordinate  a (x;y) :");
    scanf("%d%d", &a.x, &a.y);
    printf("Second coordinate b (x;y) :");
    scanf("%d%d", &b.x, &b.y);
    printf("Third coordinate c (x;y) :");
    scanf("%d%d", &c.x, &c.y);
    printf("Fourth coordinate d (x;y) :");
    scanf("%d%d", &d.x, &d.y);
   
   

    if ( ((a.x <= d.x) && (b.x <= d.x) && (c.x <= d.x)) ||((a.x >= d.x) && (b.x >= d.x) && (c.x >= d.x)) ||
         ((a.y <= d.y) && (b.y <= d.y) && (c.y <= d.y)) ||((a.y >= d.y) && (b.y >= d.y) && (c.y >= d.y)) )
     
           printf(" \n D is outside the triangle.\n");
          else printf( "\n D is inside the triangle.\n");
   
   
    getch();
    return 0;
}

Comments

Popular posts from this blog

Configure IP address on Oracle Linux

Oracle Directory Object

TIME INTERVAL in Oracle