only_maths.py
5.32 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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
import numpy as np
import cv2
# 1. Задаём кординаты треугольников в виде широты и долготы = []
prec_meas_store = [dict(station = "", coord=""),
dict(station = "", coord=""),
dict(station = "", coord=""),
dict(station = "", coord=""),
dict(station = "", coord="")] #Формат - GUID поста и GUID его параметров (координаты)
TrianglePrecipitationMeas = dict(
Name = "Измеритель осадков по данным нескольких реальных осадкомеров, построенные по принципу пространственных треугольников",
Description = "Измеритель осадков по данным нескольких реальных осадкомеров, построенные по принципу пространственных треугольников",
GUID = "",
Measure_Type_GUID = None, #measurers.mu_dmrl_precipitation.Measurer().get_reg_type_info()["GUID"],
Parameters = dict(
scale = 10,
size = 256,
triangles = [[],[],[],[]],
polygon = None #trash_data.dgubga_poligon.GetGeoCoordPolygon(),
),
Dynamic_Parameters = dict(),
Connections = dict(),
Station_Parameters = dict(),
Is_Inherited = False,
Is_Bus_Sender = True,
Is_Work = True,
Save_Addition_Info = True
)
#
#
#
#
#
#
#
#
#
#
#
#
n = 5
m = 7
an = [[1]*m] * n
print(an)
print(am)
#I ЭТАП - ОТРАБОТКА ОБЩЕГО МАТЕМАТИЧСКОГО РЕШЕНИЯ
#1. Задать три точки с координатами Р1, Р2, Р3 - (х1у1с1, х2у2с2, х3у3с3)
p1 = dict(x = 10, y = 20, z = [200, 10, 10, 112, 98, 0])
p2 = dict(x = 125, y = 200, z = [10, 200, 10, 98, 0, 45])
p3 = dict(x = 225, y = 100, z = [10, 10, 200, 0, 45, 1])
p4 = dict(x = 40, y = 180, z = [34, 48, 100, 125, 135, 200])
pts1 = np.array([[p1["x"], p1["y"]], [p2["x"], p2["y"]], [p3["x"], p3["y"]]], np.int32)
pts2 = np.array([[p1["x"], p1["y"]], [p2["x"], p2["y"]], [p4["x"], p4["y"]]], np.int32)
pts_store = (pts1, pts2)
#2. Определить "площадь решения" - по максимальным и минимальным координатам
img = np.zeros((256,256, 4),dtype=np.uint8)
#3. Нарисовать треугольник Т по трём точкам Рх
image = None
isClosedPolygon = True
color = (200, 0, 0, 0)
thickness = 1
for triangle in pts_store:
image = cv2.polylines(img, [triangle], isClosedPolygon, color, thickness)
#4. Определить формулу плоскости ПЛ по трем точкам Рх
class ChangeZPlane():
def __init__(self, _x1, _x2, _x3, _y1, _y2, _y3):
self.dx1 = _x2 - _x1
self.dx2 = _x3 - _x1
self.dy1 = _y2 - _y1
self.dy2 = _y3 - _y1
self.x1 = _x1
self.y1 = _y1
def GetIntNaturalZ(self, _z1, _z2, _z3, target_x, target_y):
result = 0
dz1 = _z2 - _z1
dz2 = _z3 - _z1
pp1 = self.dy1 * dz2 - self.dy2 * dz1
pp2 = self.dx1 * dz2 - self.dx2 * dz1
pp3 = self.dx1 * self.dy2 - self.dx2 * self.dy1
result = (((pp2 * (target_y - self.y1)) - (pp1 * (target_x - self.x1)))/(pp3)) + _z1
return result
# Example
#test = ChangeZPlane(1.0, 2.0, 0.0, -2.0, 0.0, -1.0 )
#print(test.GetIntNaturalZ(0.0, -1.0, 2.0, 1.0, 1.0))
#5. Определить формулу принадлежности произвольной точки Рн треугольнику Р1Р2Р3
def PointIsInTriangle(x1, x2, x3, y1, y2, y3, target_x, target_y):
k= (x1 - target_x) * (y2 - y1) - (x2 - x1) * (y1 - target_y)
m= (x2 - target_x) * (y3 - y2) - (x3 - x2) * (y2 - target_y)
n= (x3 - target_x) * (y1 - y3) - (x1 - x3) * (y3 - target_y)
if (k>=0 and m>=0 and n>=0) or (k<=0 and m<=0 and n<=0):
return True
else:
return False
# Example
#x = -1
#for line in image:
# x = x + 1
# y = -1
# for column in line:
# y = y + 1
# if PointIsInTriangle(10, 125, 225, 20, 200, 100, x, y):
# image[y][x] = [0,255,0,0]
#6. Пройтись по каждой точке Рпр площади решения и определить, принадлежит ли выбранная точка треугольнику Т
test = ChangeZPlane(p1["x"], p2["x"], p3["x"], p1["y"], p2["y"], p3["y"])
window_name = 'image'
zn = 0
for zn in range(6):
z1 = p1["z"][zn]
z2 = p2["z"][zn]
z3 = p3["z"][zn]
x = -1
for line in image:
x = x + 1
y = -1
for column in line:
y = y + 1
if PointIsInTriangle(p1["x"], p2["x"], p3["x"], p1["y"], p2["y"], p3["y"], x, y):
#image[y][x] = [0,255,0,0]
color = int(test.GetIntNaturalZ(z1,z2,z3,x,y))
image[y][x] = [0,color,0,0]
cv2.imshow('image', image)
cv2.waitKey(0)
cv2.destroyAllWindows()
#8. Сохранить результат в виде рисунка png и (показать результат)
# Displaying the image
#while(1):
#
# cv2.imshow('image', image)
# if cv2.waitKey(20) & 0xFF == 27:
# break
#
#cv2.destroyAllWindows()