Repository navigation
Expand file tree
/
Copy pathtests.cc
More file actions
executable file
·97 lines (74 loc) · 2.13 KB
/
Copy pathtests.cc
File metadata and controls
executable file
·97 lines (74 loc) · 2.13 KB
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#include <iostream>
#include <string>
#include <math.h>
#include <float.h>
#include <cmath>
#include <stdio.h>
using namespace std;
void getIntersectionPoint() {
double x1, x2, x3, x4, y1, y2, y3, y4;
double m1, m2;
double x, y;
// Se definen los puntos
// x1 = pointOne->getX();
// y1 = pointOne->getY();
// x2 = pointTwo->getX();
// y2 = pointTwo->getY();
// x3 = pointThree->getX();
// y3 = pointThree->getY();
// x4 = pointFour->getX();
// y4 = pointFour->getY();
x1 = 0.3;
y1 = 0.25;
x2 = 0.6;
y2 = 0.25;
x3 = 0.6;
y3 = 0.493535;
x4 = 0.345726;
y4 = 0.736448;
// Dos rectas paralelas verticales
// if (fabs(x2 - x1) < FLT_EPSILON && fabs(x4 - x3) < FLT_EPSILON) {
if ((x2 - x1) == 0 && (x4 - x3) == 0) {
//return NULL;
printf("NULL\n");
}
// Una recta vertical y otra no
// else if (fabs(x2 - x1) < FLT_EPSILON && fabs(x4 - x3) > FLT_EPSILON) {
else if ((x2 - x1) == 0 && (x4 - x3) != 0) {
// m1 -> infinito and m2 pertenece a los reales
m2 = (y4 - y3) / (x4 - x3);
x = x1;
y = m2 * (x1 - x3) + y3;
//return new Point2D(x, y);
printf("(%lf, %lf)\n", x, y)
}
// else if (fabs(x2 - x1) > FLT_EPSILON && fabs(x4 - x3) < FLT_EPSILON) {
else if ((x2 - x1) != 0 && (x4 - x3) == 0) {
// m2 -> infinito and m1 pertenece a los reales
m1 = (y2 - y1) / (x2 - x1);
x = x3;
y = m1 * (x3 - x1) + y1;
//return new Point2D(x, y);
printf("(%lf, %lf)\n", x, y);
}
else {
m1 = (y2 - y1) / (x2 - x1);
m2 = (y4 - y3) / (x4 - x1);
// Rectas paralelas
// if (fabs(m1 - m2) < FLT_EPSILON) {
if (m1 == m2) {
//return NULL;
printf("NULL\n");
}
else {
x = (m1 * x1 - y1 + y3 - m2 * x3) / (m1 - m2);
y = (m1 * m2 * (x1 - x3) + y3 * m1 - y1 * m2) / (m1 - m2);
//return new Point2D(x, y);
printf("(%lf, %lf)\n", x, y);
}
}
}
int main(int argc, char** argv) {
getIntersectionPoint();
return 1;
}