science_action
w
import random
import pprint
import math
import matplotlib.pyplot as plt def gen_random(magnify_=1000, round_=2):
dd = round(random.random() * magnify_, round_)
return dd def float_format(d, not_float=0.0):
if d is float:
print(232)
else:
try:
d = float(d)
except Exception:
d = not_float
return d def gen_atob_dis(a, b):
a, b = float_format(a), float_format(b)
return ((a ** 2 + b ** 2) * 0.5) ** 0.5 def chk_triangle(a, b, c):
a, b, c = float_format(a), float_format(b), float_format(c)
if a + b > c and a + c > b and b + c > a:
return 1
else:
return 0 def compute_triangle_angle(a, b, c):
a, b, c = float_format(a), float_format(b), float_format(c)
cos = (a ** 2 + b ** 2 - c ** 2) / (2 * a * b)
return math.acos(cos) def radius_coordinates_to_perpendicular_coordinates(dic_):
polar_radius, polar_angle = dic_['polar_radius'], dic_['polar_angle']
res_ = {}
res_['y'], res_['x'] = polar_radius * math.sin(polar_angle), polar_radius * math.cos(polar_angle)
return res_ PI = math.pi
uuid_num = 5
uuid_num_plus = uuid_num + 1
str_ = '-86 -83 -71 -69 -73 -60 -72 -84 -82 -56 -82 -75 -71 -89 -83 -79 -67 -87 -77 -79' l_row = str_.split('\t\t\t')
rssi_matrix = {}
for i in range(0, uuid_num, 1):
i_ = i + 1
rssi_matrix[i_] = {}
l_one = l_row[i].split('\t')
step_ = 0
for ii in range(0, uuid_num, 1):
ii_ = ii + 1
if i == ii:
rssi_matrix[i_][ii_] = 0
else:
rssi_matrix[i_][ii_] = l_one[step_]
step_ += 1 rssi_distance_matrix = {}
for i in range(0, uuid_num, 1):
i_ = i + 1
rssi_distance_matrix[i_] = {}
for ii in range(0, uuid_num, 1):
ii_ = ii + 1
a = rssi_matrix[i_][ii_]
b = rssi_matrix[ii_][i_]
rssi_distance_matrix[i_][ii_] = gen_atob_dis(a, b)
pprint.pprint(str_)
pprint.pprint(rssi_matrix)
pprint.pprint(rssi_distance_matrix) triangle_dic = {}
triangle_side_list = []
for i in range(1, uuid_num_plus, 1):
for ii in range(1, uuid_num_plus, 1):
for iii in range(1, uuid_num_plus, 1):
if i != ii and i != iii and ii != iii:
triangle_id = '%s%s%s' % (i, ii, iii)
chk_unique_triangle_id_list = sorted(list(triangle_id))
if chk_unique_triangle_id_list in triangle_side_list:
continue
triangle_side_list.append(chk_unique_triangle_id_list)
triangle_dic[triangle_id] = {}
triangle_dic[triangle_id]['length_of_side_dic'] = []
triangle_dic[triangle_id]['is_triangle'] = 0
c = rssi_distance_matrix[i][ii]
b = rssi_distance_matrix[i][iii]
a = rssi_distance_matrix[ii][iii]
is_triangle = chk_triangle(a, b, c)
triangle_dic[triangle_id]['is_triangle'] = is_triangle
if is_triangle == 1:
triangle_dic[triangle_id]['length_of_side_dic'] = {}
triangle_dic[triangle_id]['angle_of_side_dic'] = {}
k12 = '%s%s' % (i, ii)
k13 = '%s%s' % (i, iii)
k23 = '%s%s' % (ii, iii)
triangle_dic[triangle_id]['length_of_side_dic'][k12] = a
triangle_dic[triangle_id]['length_of_side_dic'][k13] = b
triangle_dic[triangle_id]['length_of_side_dic'][k23] = c # filter_ triangle rebuild
radius_coordinates = {}
radius_coordinates[1] = {}
radius_coordinates[1]['polar_angle'] = 0
radius_coordinates[1]['polar_radius'] = 0
radius_coordinates[2] = {}
radius_coordinates[2]['polar_radius'] = rssi_distance_matrix[1][2]
radius_coordinates[2]['polar_angle'] = 0
radius_coordinates[3] = {}
radius_coordinates[3]['polar_radius'] = rssi_distance_matrix[1][3]
a = rssi_distance_matrix[1][2]
b = rssi_distance_matrix[1][3]
c = rssi_distance_matrix[2][3]
radius_coordinates[3]['polar_angle'] = abs(compute_triangle_angle(a, b, c)) for i in range(4, uuid_num_plus, 1):
radius_coordinates[i] = {}
radius_coordinates[i]['polar_radius'] = 0
radius_coordinates[i]['polar_angle'] = 0 polar_radius_i = rssi_distance_matrix[1][i] a = rssi_distance_matrix[1][2]
c = rssi_distance_matrix[2][i]
angle_radius_from12 = compute_triangle_angle(a, polar_radius_i, c) a = rssi_distance_matrix[1][3]
c = rssi_distance_matrix[3][i]
angle_radius_from13 = compute_triangle_angle(a, polar_radius_i, c) polar_angle_i = angle_radius_from12
if abs(angle_radius_from12) + radius_coordinates[3]['polar_angle'] == angle_radius_from13:
polar_angle_i = 2 * PI - angle_radius_from12
radius_coordinates[i]['polar_radius'] = polar_radius_i
radius_coordinates[i]['polar_angle'] = polar_angle_i perpendicular_coordinates = {}
for i in range(1, uuid_num_plus, 1):
dic_ = radius_coordinates[i]
res_ = radius_coordinates_to_perpendicular_coordinates(dic_)
perpendicular_coordinates[i] = {}
perpendicular_coordinates[i]['x'], perpendicular_coordinates[i]['y'] = res_['x'], res_['y'] x = [perpendicular_coordinates[i]['x'] for i in range(1, uuid_num_plus, 1)]
y = [perpendicular_coordinates[i]['y'] for i in range(1, uuid_num_plus, 1)] for i in range(1, 4, 1):
pprint.pprint(perpendicular_coordinates[i])
plt.plot(x, y)
plt.show()
science_action的更多相关文章
随机推荐
- Vue 基础 day03
定义Vue 组件 什么是组件:组件的出现,就是为了拆分 Vue 实例的代码量,能够让我们以不同的组件,来划分不同的功能模块,将来我们需要什么样的功能,就可以去调用对应的组件: 组件化和模块化的不同: ...
- [Web 前端] 001 html 常用块级标签
目录 1. html "总体框架" 2. 常用的 HTML 块级标签(块元素) 2.1 知识点 2.2 以下 code 均写在 body 体中 2.2.1 标题标签,只有 h1-h ...
- webpack4 es6转换
在webpack里用es6语法, ie浏览器不识别,为了让浏览器识别,需要用到bebal转换; bebal,英文是通天塔 的意思, 我们常说的巴比伦也是这个词;我估计是当初设计者是想用它作为一个沟通e ...
- Java学习day7面向对象编程1-对象和类
一.Java编程中对象和类的概念 1,什么是类? 答:类是客观存在的,抽象的,概念的东西. 2,什么是对象? 答:对象是具体的,实际的,代表一个事物.例如:车是一个类,汽车,自行车就是他的对象. 关于 ...
- .net core jessetalk资料合集
资料推荐集合贴 By Jesse • 2018-01-10 • 5064次浏览 流程图在线预览地址:https://9o90oe.axshare.com/#g=1&p=home OAuth2 ...
- 06-File-文件
文件 长久保存信息的一种数据信息集合 常用操作 打开关闭(文件一旦打开,需要关闭操作) 读写内容 查找 open函数 open函数负责打开文件,带有很多参数 第一个参数: 必须有,文件的路径和名称 m ...
- 实体模型集合对象转换为VO对象集合
例如: 数据库中查出来的数据为 List<RptDayMonthTarget> List<RptDayMonthTarget> list = targetService.sel ...
- Java JNA (五)—— 释放Memory对象分配的内存
Java进程的内存包括Java NonHeap空间.Java Heap空间和Native Heap空间. JNA中的Memory对象是从Native Heap中分配空间.但java的GC是针对Java ...
- docker安装es
下载镜像 docker pull docker.elastic.co/elasticsearch/elasticsearch:6.8.1 创建容器并映射docker run -e ES_JAVA_OP ...
- 03机器学习实战之决策树scikit-learn实现
sklearn.tree.DecisionTreeClassifier 基于 scikit-learn 的决策树分类模型 DecisionTreeClassifier 进行的分类运算 http://s ...