绘制桌子和红外阵列的相对位置

import json
import matplotlib.pyplot as plt


class IR_sensor:
    IR_high = [2.81, 2.813, 2.803, 2.968, 2.808, 2.804, 2.704, 3.1, 2.694, 2.801, 2.806, 2.815, 2.668, 2.638, 2.8,
               2.799, 2.8, 2.8, 2.723]
    IR_sensor_dir = 'IR_sensor.json'
    IR_position = json.load(open(IR_sensor_dir))
    IR_default_size = 3.6
    IR_area_shrink = {3: {'Up': 0}, 4: {'Up': 1}, 5: {'Up': 1, 'Left': 1}, 6: {'Up': 1, 'Down': 1}, 7: {'Up': 1},
                      8: {'Up': 1, 'Right': 2}, 9: {'Up': 1, 'Down': 1}, 10: {'Down': 1, 'Up': 1},
                      11: {'Right': 1, 'Down': 1, 'Up': 1}, 12: {'Left': 0}, 13: {'Right': 1},
                      14: {'Down': 1, 'Left': 1}, 15: {'Up': 1, 'Down': 1}, 16: {'Up': 1, 'Down': 1},
                      17: {'Right': 1}, 18: {'Down': 0}, 19: {'Right': 1, 'Left': 1}, 20: {'Left': 2},
                      21: {'Left': 2, 'Up': 1}}
    IR_Real_size = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]

    def __init__(self):
        self.cal_IR_size()
        self.draw_normal_direction()
        self.draw_rotate_direction()

    def cal_IR_size(self):
        for i in range(len(self.IR_high)):
            self.IR_Real_size[i + 3] = (self.IR_high[i] / 2.7) * self.IR_default_size

    def draw_normal_direction(self):
        for i in range(3, 22):
            if i not in [12, 13, 17, 18]:
                x_start = self.IR_position[0][str(i)][0] - self.IR_Real_size[i] / 2
                y_start = self.IR_position[0][str(i)][1] - self.IR_Real_size[i] / 2
                x_size = self.IR_Real_size[i]
                y_size = self.IR_Real_size[i]

                if 'Up' in self.IR_area_shrink[i]:
                    y_size -= self.IR_Real_size[i] * self.IR_area_shrink[i]['Up'] / 4

                if 'Down' in self.IR_area_shrink[i]:
                    y_start += self.IR_Real_size[i] * self.IR_area_shrink[i]['Down'] / 4
                    y_size -= self.IR_Real_size[i] * self.IR_area_shrink[i]['Down'] / 4

                if 'Left' in self.IR_area_shrink[i]:
                    x_start += self.IR_Real_size[i] * self.IR_area_shrink[i]['Left'] / 4
                    x_size -= self.IR_Real_size[i] * self.IR_area_shrink[i]['Left'] / 4

                if 'Right' in self.IR_area_shrink[i]:
                    x_size -= self.IR_Real_size[i] * self.IR_area_shrink[i]['Right'] / 4
                rect = plt.Rectangle([x_start, y_start], x_size, y_size, edgecolor='y', facecolor='none')
                plt.gca().add_patch(rect)
                self.draw_text_and_center(i)

    def draw_rotate_direction(self):
        for i in [12, 13, 17, 18]:
            x_start = self.IR_position[0][str(i)][0]
            y_start = self.IR_position[0][str(i)][1]
            x_size = self.IR_Real_size[i] / 4
            y_size = self.IR_Real_size[i] / 2
            rect1 = plt.Rectangle([x_start, y_start], x_size, y_size, edgecolor='y', facecolor='none', angle=-25)

            x_size = -self.IR_Real_size[i] / 2
            y_size = -self.IR_Real_size[i] / 2
            rect2 = plt.Rectangle([x_start, y_start], x_size, y_size, edgecolor='y', facecolor='none', angle=-25)

            x_size = -self.IR_Real_size[i] / 2
            y_size = self.IR_Real_size[i] / 2
            rect3 = plt.Rectangle([x_start, y_start], x_size, y_size, edgecolor='y', facecolor='none', angle=-25)

            x_size = self.IR_Real_size[i] / 4
            y_size = -self.IR_Real_size[i] / 2
            rect4 = plt.Rectangle([x_start, y_start], x_size, y_size, edgecolor='y', facecolor='none', angle=-25)
            plt.gca().add_patch(rect1)
            plt.gca().add_patch(rect2)
            plt.gca().add_patch(rect3)
            plt.gca().add_patch(rect4)
            self.draw_text_and_center(i)

    def draw_text_and_center(self, i):
        x_center = self.IR_position[0][str(i)][0]
        y_center = self.IR_position[0][str(i)][1]
        plt.text(x_center + 0.5, y_center, i, fontsize=12, color='r')
        cir1 = plt.Circle(xy=(x_center, y_center), radius=0.1, color='r')
        plt.gca().add_patch(cir1)

# fig = plt.figure()
# plt.xlim(-11, 11)
# plt.ylim(-22, 0)
# IR_sensor1 = IR_sensor()
# # IR_sensor1.draw_desk_by_center()
# # IR_sensor1.draw_desk_by_edge()
# plt.show()

 

import json
import matplotlib.pyplot as plt


class desk:
    desk_center_dir = 'filter_data.json'
    desk_edge_dir = 'filter_data_3point.json'
    desk_center = json.load(open(desk_center_dir))
    desk_edge = json.load(open(desk_edge_dir))
    desk_type = ['x', 'C', 'C', 'C', 'C', 'C', 'C', 'B', 'A', 'A', 'B', 'B', 'B', 'B', 'E', 'E', 'B', 'B', 'B', 'D',
                 'A', 'A', 'A', 'A', 'A', 'A', 'A']
    desk_type_size = dict(A=[0.91, 0.91], B=0.5, C=[0.91, 0.91 * 2], D=0.75, E=[2.5, 1.1])

    def __init__(self):
        self.draw_desk_by_center()
        self.draw_desk_by_edge()

    def draw_desk_by_center(self):
        for i in range(7, 27):
            print(i)
            if self.desk_type[i] in ['A', 'E']:
                x_start = self.desk_center[0][str(i)][0] - self.desk_type_size[self.desk_type[i]][0] / 2
                y_start = self.desk_center[0][str(i)][1] - self.desk_type_size[self.desk_type[i]][1] / 2
                x_size = self.desk_type_size[self.desk_type[i]][0]
                y_size = self.desk_type_size[self.desk_type[i]][1]
                rect = plt.Rectangle([x_start, y_start], x_size, y_size, color='deepskyblue')
                plt.gca().add_patch(rect)
                text_x = self.desk_center[0][str(i)][0] + 0.5
                text_y = self.desk_center[0][str(i)][1]

            elif self.desk_type[i] in ['B', 'D']:
                x_start = self.desk_center[0][str(i)][0]
                y_start = self.desk_center[0][str(i)][1]
                cir1 = plt.Circle(xy=(x_start, y_start), radius=self.desk_type_size[self.desk_type[i]], color='deepskyblue')
                text_x = self.desk_center[0][str(i)][0] + 0.5
                text_y = self.desk_center[0][str(i)][1]
                plt.gca().add_patch(cir1)
            plt.text(text_x, text_y, i, fontsize=12)

    def draw_desk_by_edge(self):
        for i in range(1, 7):
            print(self.desk_edge[0][str(i)])
            plt.plot([self.desk_edge[0][str(i)][0], self.desk_edge[1][str(i)][0]],
                     [self.desk_edge[0][str(i)][1], self.desk_edge[1][str(i)][1]])
            plt.plot([self.desk_edge[0][str(i)][0], self.desk_edge[2][str(i)][0]],
                     [self.desk_edge[0][str(i)][1], self.desk_edge[2][str(i)][1]])
            plt.text(self.desk_edge[0][str(i)][0] + 0.5, self.desk_edge[0][str(i)][1], i, fontsize=12)


# fig = plt.figure()
# plt.xlim(-11, 11)
# plt.ylim(-22, 0)
# desk1 = desk()
# plt.show()

 

import matplotlib.pyplot as plt
from IR_sensor import IR_sensor
from desk import desk

if __name__ == '__main__':
    fig = plt.figure()
    plt.xlim(-11, 11)
    plt.ylim(-22, 0)
    desk1 = desk()
    IR_sensor1 = IR_sensor()
    plt.show()

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值