Mam następujące zadanko:
A oto moje rozwiazanie:
#include <iostream>
#include <math.h>
#include <string>
using namespace std;int gdzie_lezy(double x1, double y1, double x2, double y2, double x3, double y3, double x, double y);
int prosta(double x1, double y1, double x2, double y2, double x, double y);int main()
{
double x1, y1, x2, y2, x3, y3, x, y;
while(true)
{
cin >> x1;
cin >> y1;
cin >> x2;
cin >> y2;
cin >> x3;
cin >> y3;
cin >> x;
cin >> y;if (x1 == 0 && y1 == 0 && x2 == 0 && y2 == 0 && x3 == 0 && y3 == 0 && x == 0 && y == 0) { break; } else { gdzie_lezy( x1, y1, x2, y2, x3, y3, x, y); } } return 0;
}
int gdzie_lezy(double x1, double y1, double x2, double y2, double x3, double y3, double x, double y)
{
int a = prosta(x1, y1, x2, y2, x, y);
int b = prosta(x1, y1, x3, y3, x, y);
int c = prosta(x2, y2, x3, y3, x, y);
int test_a = prosta(x1, y1, x2, y2, x3, y3);
int test_b = prosta(x1, y1, x3, y3, x2, y2);
int test_c = prosta(x2, y2, x3, y3, x1, y1);if(a == 0 or b == 0 or c == 0) { cout << "E" << endl; return 0; } // sprawdzamy czy punkt oraz trzeci wierzchołek leżą po tej samej stronie prostej wyznaczanej przez pozostałe dwa punkty trójkąta if (test_a * a <0 or test_b * b <0 or test_c * c <0) { cout << "O" << endl; return 0; } else { cout << "I" << endl; return 0; }
}
int prosta(double x1,double y1,double x2,double y2,double x,double y)
{
int a,b;
if (x1 > x2)
{
a = x2;
b = x1;
}
else
{
a = x1;
b = x2;
}if(((y2-y1)/(x2-x1) * x + y1 - x1*(y2-y1)/(x2-x1)) == y && x >= a && x <= b) { // punkt leży na krawędzi return 0; } if( (y2-y1)/(x2-x1) * (x - x1) + y1 > y) { // punkt leży pod prostą return -1; } else { // punkt leży nad prostą return 1; }
}
Poproszę o korektę.