python利用中心坐标绘制矩形

python利用matplotlib库根据中心坐标与方位角绘制矩形

import matplotlib.pyplot as plt
import math
def convert_center_to_leftdown(x_cord, y_cord, angle, width, height):
    xp = x_cord-(math.sqrt(width**2+height**2)/2)*math.cos(math.atan2(height, width)+angle/180*math.pi)
    yp = y_cord-(math.sqrt(width**2+height**2)/2)*math.sin(math.atan2(height, width)+angle/180*math.pi)
    return xp, yp


fig1 = plt.figure()   # 确保正方形在屏幕上显示一致,固定figure的长宽相等
axes1 = fig1.add_subplot(1, 1, 1)
# 输入矩形中心坐标,矩形方位角(逆时针为正)以及矩形的宽与高即可绘制矩形
x = 0.5
y = 0.5
phi = -30
w = 0.2
h = 0.1
xp, yp = convert_center_to_leftdown(x, y, phi, w, h)
square = plt.Rectangle(xy=(xp, yp), width=w, height=h, alpha=0.8, angle=phi)
axes1.add_patch(square)  # 把图形加载到绘制区域
axes1.axis('equal')
axes1.grid()
plt.show()

在这里插入图片描述

  • 0
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值