подсчет высоты

 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
float countHeightsimple(int triangleIndex, PVectorExt P) {
final int c = triangleIndex * 3;
PVectorExt A = delaunayTriangulation.g(c);
PVectorExt B = delaunayTriangulation.g(delaunayTriangulation.n(c));
PVectorExt C = delaunayTriangulation.g(delaunayTriangulation.p(c));
if (((A.v.x == P.v.x) && (A.v.y == P.v.y))) {
println("matched with vertex A");
return A.h;
}
if (((B.v.x == P.v.x) && (B.v.y == P.v.y))) {
println("matched with vertex B");
return B.h;
}
if (((C.v.x == P.v.x) && (C.v.y == P.v.y))) {
println("matched with vertex C");
return C.h;
}
if (isInsideSegment(A.v, B.v, P.v)) {
println("on edge");
float a = (B.h - A.h)/(B.v.x - A.v.x);
float b = (A.h * B.v.x - B.h * A.v.x)/(B.v.x - A.v.x);
return a * P.v.x + b;
}
if (isInsideSegment(B.v, C.v, P.v)) {
println("on edge");
float a = (C.h - B.h)/(C.v.x - B.v.x);
float b = (B.h * C.v.x - C.h * B.v.x)/(C.v.x - B.v.x);
return a * P.v.x + b;
}
if (isInsideSegment(A.v, C.v, P.v)) {
println("on edge");
float a = (C.h - A.h)/(C.v.x - A.v.x);
float b = (A.h * C.v.x - C.h * A.v.x)/(C.v.x - A.v.x);
return a * P.v.x + b;
}
float Sabc = countS(A, B, C);
float TV = Sabc * (A.h + B.h + C.h);
float h3 = (TV - countS(A, B, P) * (A.h + B.h) - countS(B, C, P) * (B.h + C.h) - countS(P, C, A) * (A.h + C.h)) / (countS(A, B, P) + countS(B, C, P) + countS(P, C, A));
if (h3 < 0) {
println("below zero in h3!!! A: " + A.v + "B: " + B.v + "C: " + C.v);
}
return h3;
}
float countS(PVectorExt A, PVectorExt B, PVectorExt C) {
float S = (B.v.x - A.v.x) * (C.v.y - A.v.y) - (C.v.x - A.v.x) * (B.v.y - A.v.y);
if (S < 0) {
//println("S below zero, change");
S = -S;
}
return S;
}