Geometry in C++

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include <math>
using namespace std;
//dlina mezhdu tochkami na koordinatnoy pryamoy
long long lenth (int x1,int y1,int x2,int y2){
int t1=x1-x2;
int t2=y1-y2;
return sqrt(pow(t1,2)+pow(t2,2));
}
//ploshad' treugol'nika
long long squaretr(int x1,int y1,int x2,int y2,int x3,int y3){
int t1=x2-x1;
int t2=y3-y1;
int t3=x3-x1;
int t4=y2-y1;
t1=(t1*t2)-(t3*t4);
t1/=2;
if(t1<0){t1*=-1;}
return t1;
}
//nahoditsya li tochka v treugul'nike
int pointintriangle (int x1,int y1,int x2,int y2,int x3,int y3,int x4,int y4){
if((squaretr(x1,y1,x2,y2,x4,y4)+squaretr(x1,y1,x3,y3,x4,y4)+squaretr(x2,y2,x3,y3,x4,y4))==squaretr(x1,y1,x2,y2,x3,y3)){return 1;}
return 0;
}