This repository has been archived by the owner on Dec 16, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathExaRandomMachine.py
96 lines (87 loc) · 3.5 KB
/
ExaRandomMachine.py
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
from panda3d.core import VBase3
import Submap
import random
import math
vertices_exa = [VBase3(1, -1, 0), VBase3(1, 0, -1), VBase3(0, 1, -1)] # q,w,e (top corners)
class ExaRandom:
def randomize_values(self, number_of_values, mid_value, max_diff, negative):
rnd_list = [(0, round(max_diff*0.10))] * 80 + [(round(max_diff*0.11), round(max_diff*0.4))] * 15 + [(round(max_diff*0.41), max_diff)] * 5
result = []
for i in range(0, number_of_values):
chosen = random.choice(rnd_list)
if negative:
result.append(mid_value + round(random.randint(chosen[0], chosen[1]) / 10 * random.choice([-1, 1])))
else:
result.append(mid_value + round(random.randint(chosen[0], chosen[1]) / 10))
return result
def create_submap(self, submapXY):
rnd_Z = self.randomize_values(7, 0, 100, False)
rnd_T = self.randomize_values(7, 10, 80, True)
rnd_H = self.randomize_values(7, 40, 50, True)
rnd_seed = random.randint(0,100)
return Submap.Submap(submapXY, rnd_Z, rnd_T, rnd_H, rnd_seed)
def interpolate(self, vABC, radius, exaP):
(zA, zB, zC) = vABC[0]
(tA, tB, tC) = vABC[1]
(hA, hB, hC) = vABC[2]
(eP, xP, aP) = exaP
vertex_index = None
if aP <= 0 and xP < 0: # qw triangle
vertex_index = 0
elif xP >= 0 and eP > 0: # we triangle
vertex_index = 1
elif eP <= 0 and aP < 0: # ed triangle
vertex_index = 2
elif aP >= 0 and xP > 0: # ds triangle
vertex_index = 0
radius = -radius
elif xP <= 0 and eP < 0: # sa triangle
vertex_index = 1
radius = -radius
elif eP >= 0 and aP > 0: # aq triangle
vertex_index = 2
radius = -radius
(eB, xB, aB) = vertices_exa[vertex_index]*radius
(eC, xC, aC) = vertices_exa[(vertex_index+1)%3]*radius
# 1) each vertex influences P according to the inverse of the distance
wA = 1 / max(abs(eP), abs(xP), abs(aP))
wB = 1 / max(abs(eB - eP), abs(xB - xP), abs(aB - aP))
wC = 1 / max(abs(eC - eP), abs(xC - xP), abs(aC - aP))
"""
# 2) the influence of each vertex on P scales with the inverse of the distance^2
dA = max(abs(eP), abs(xP), abs(aP))
dB = max(abs(eB - eP), abs(xB - xP), abs(aB - aP))
dC = max(abs(eC - eP), abs(xC - xP), abs(aC - aP))
wA = 1 / pow(dA, 2)
wB = 1 / pow(dB, 2)
wC = 1 / pow(dC, 2)
"""
"""
# 3) the influence of each vertex on P scales with the inverse of the distance, 0 on d=radius
dA = max(abs(eP), abs(xP), abs(aP))
dB = max(abs(eB - eP), abs(xB - xP), abs(aB - aP))
dC = max(abs(eC - eP), abs(xC - xP), abs(aC - aP))
wA = 1 / dA
wB = 1 / dB
wC = 1 / dC
if dA==radius:
wA=0
elif dB==radius:
wB=0
elif dC==radius:
wC=0
"""
"""
# 4) Barycentric coordinates way (not working correctly, problem on last triangle)
eB_eC = eB-eC
xC_xB = xC-xB
eP_eC = eP-eC
xP_xC = xP-xC
divisore = eB_eC*-xC + xC_xB*-eC
wA = (eB_eC*xP_xC + xC_xB*eP_eC) / divisore
wB = (eC*xP_xC + -xC*eP_eC) / divisore
wC = 1 - wA - wB
"""
return ((wA*zA + wB*zB + wC*zC)/(wA+wB+wC),
(wA*tA + wB*tB + wC*tC)/(wA+wB+wC),
(wA*hA + wB*hB + wC*hC)/(wA+wB+wC))