I need some help with my homework. I tried hard to do this and I failed.
We have a triangle with coordinates: A=(-4,4), B=(4,-2), C=(6,6). I need to load from user coordinates of point P=(x,y) and then write on the screen information telling if point P is laying in, out, or on the side of the triangle.
That's what I made this far:
class Program
{
static void Main(string[] args)
{
const int x1 = -4, y1 = 4;
const int x2 = 4, y2 = -2;
const int x3 = 6, y3 = 6;
int x0, y0;
Console.Write("Podaj współrzędną x: ");
x0 = Convert.ToInt32(Console.ReadLine());
Console.Write("Podaj współrzędną y: ");
y0 = Convert.ToInt32(Console.ReadLine());
double A_AB = (y2 - y1 / x2 - x1);
double B_AB = (y1 - (y2 - y1 / x2 - x1) * x1);
double A_AC = (y3 - y1 / x3 - x1);
double B_AC = (y1 - (y3 - y1 / x3 - x1) * x1);
double A_BC = (y3 - y2 / x3 - x2);
double B_BC = (y2 - (y3 - y2 / x3 - x2) * x2);
if ((y0 > (A_AB * x0 + B_AB) && y0 > (A_AC * x0 + B_AC) && y0 > (A_BC * x0 + B_BC))) Console.WriteLine("Point is inside of the triangle.");
else if (y0 == (A_AB * x0 + B_AB) || y0 == (A_AC * x0 + B_AC) || y0 == (A_BC * x0 + B_BC)) Console.WriteLine("Point is on the side of the triangle");
else Console.WriteLine("Point is outside of the triangle.");
Console.ReadKey(true);
}
}
Something is wrong, cause it's hard to hit space in the triangle. Would somebody analyse this? My brain is burning.
Thanks.