开源 企业版 高校版 私有云 模力方舟 AI 队友
代码拉取完成,页面将自动刷新
捐赠
捐赠前请先登录
扫描微信二维码支付
取消
支付完成
支付提示
将跳转至支付宝完成支付
确定
取消
1 Star 0 Fork 45

zerosl/PythonRobotics

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
已有帐号? 立即登录
文件
master
分支 (67)
标签 (1)
master
dependabot/pip/requirements/ruff-0.1.13
dependabot/pip/requirements/ruff-0.1.9
AtsushiSakai-patch-1-1
support_python_12
dependabot/pip/requirements/mypy-1.7.1
dependabot/pip/requirements/ruff-0.1.5
dependabot/pip/requirements/mypy-1.7.0
dependabot/pip/requirements/numpy-1.26.2
dependabot/pip/requirements/pytest-7.4.3
dependabot/pip/requirements/ruff-0.1.1
dependabot/pip/requirements/mypy-1.6.1
dependabot/pip/requirements/ruff-0.0.292
dependabot/pip/requirements/ruff-0.0.291
dependabot/pip/requirements/pytest-7.4.2
dependabot/pip/requirements/ruff-0.0.287
dependabot/pip/requirements/pytest-7.4.1
dependabot/github_actions/actions/checkout-4
dependabot/pip/requirements/ruff-0.0.286
gh-pages
v1.0
master
分支 (67)
标签 (1)
master
dependabot/pip/requirements/ruff-0.1.13
dependabot/pip/requirements/ruff-0.1.9
AtsushiSakai-patch-1-1
support_python_12
dependabot/pip/requirements/mypy-1.7.1
dependabot/pip/requirements/ruff-0.1.5
dependabot/pip/requirements/mypy-1.7.0
dependabot/pip/requirements/numpy-1.26.2
dependabot/pip/requirements/pytest-7.4.3
dependabot/pip/requirements/ruff-0.1.1
dependabot/pip/requirements/mypy-1.6.1
dependabot/pip/requirements/ruff-0.0.292
dependabot/pip/requirements/ruff-0.0.291
dependabot/pip/requirements/pytest-7.4.2
dependabot/pip/requirements/ruff-0.0.287
dependabot/pip/requirements/pytest-7.4.1
dependabot/github_actions/actions/checkout-4
dependabot/pip/requirements/ruff-0.0.286
gh-pages
v1.0
克隆/下载
克隆/下载
提示
下载代码请复制以下命令到终端执行
为确保你提交的代码身份被 Gitee 正确识别,请执行以下命令完成配置
初次使用 SSH 协议进行代码克隆、推送等操作时,需按下述提示完成 SSH 配置
1 生成 RSA 密钥
2 获取 RSA 公钥内容,并配置到 SSH公钥
在 Gitee 上使用 SVN,请访问 使用指南
使用 HTTPS 协议时,命令行会出现如下账号密码验证步骤。基于安全考虑,Gitee 建议 配置并使用私人令牌 替代登录密码进行克隆、推送等操作
Username for 'https://gitee.com': userName
Password for 'https://userName@gitee.com': # 私人令牌
master
分支 (67)
标签 (1)
master
dependabot/pip/requirements/ruff-0.1.13
dependabot/pip/requirements/ruff-0.1.9
AtsushiSakai-patch-1-1
support_python_12
dependabot/pip/requirements/mypy-1.7.1
dependabot/pip/requirements/ruff-0.1.5
dependabot/pip/requirements/mypy-1.7.0
dependabot/pip/requirements/numpy-1.26.2
dependabot/pip/requirements/pytest-7.4.3
dependabot/pip/requirements/ruff-0.1.1
dependabot/pip/requirements/mypy-1.6.1
dependabot/pip/requirements/ruff-0.0.292
dependabot/pip/requirements/ruff-0.0.291
dependabot/pip/requirements/pytest-7.4.2
dependabot/pip/requirements/ruff-0.0.287
dependabot/pip/requirements/pytest-7.4.1
dependabot/github_actions/actions/checkout-4
dependabot/pip/requirements/ruff-0.0.286
gh-pages
v1.0
plot.py 8.49 KB
一键复制 编辑 原始数据 按行查看 历史
Atsushi Sakai 提交于 2023年07月06日 22:12 +08:00 . Adding NDT mapping script and doc (#867)
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 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234
"""
Matplotlib based plotting utilities
"""
import math
import matplotlib.pyplot as plt
import numpy as np
from mpl_toolkits.mplot3d import art3d
from matplotlib.patches import FancyArrowPatch
from mpl_toolkits.mplot3d.proj3d import proj_transform
from mpl_toolkits.mplot3d import Axes3D
from utils.angle import rot_mat_2d
def plot_covariance_ellipse(x, y, cov, chi2=3.0, color="-r", ax=None):
"""
This function plots an ellipse that represents a covariance matrix. The ellipse is centered at (x, y) and its shape, size and rotation are determined by the covariance matrix.
Parameters:
x : (float) The x-coordinate of the center of the ellipse.
y : (float) The y-coordinate of the center of the ellipse.
cov : (numpy.ndarray) A 2x2 covariance matrix that determines the shape, size, and rotation of the ellipse.
chi2 : (float, optional) A scalar value that scales the ellipse size. This value is typically set based on chi-squared distribution quantiles to achieve certain confidence levels (e.g., 3.0 corresponds to ~95% confidence for a 2D Gaussian). Defaults to 3.0.
color : (str, optional) The color and line style of the ellipse plot, following matplotlib conventions. Defaults to "-r" (a red solid line).
ax : (matplotlib.axes.Axes, optional) The Axes object to draw the ellipse on. If None (default), a new figure and axes are created.
Returns:
None. This function plots the covariance ellipse on the specified axes.
"""
eig_val, eig_vec = np.linalg.eig(cov)
if eig_val[0] >= eig_val[1]:
big_ind = 0
small_ind = 1
else:
big_ind = 1
small_ind = 0
a = math.sqrt(chi2 * eig_val[big_ind])
b = math.sqrt(chi2 * eig_val[small_ind])
angle = math.atan2(eig_vec[1, big_ind], eig_vec[0, big_ind])
plot_ellipse(x, y, a, b, angle, color=color, ax=ax)
def plot_ellipse(x, y, a, b, angle, color="-r", ax=None, **kwargs):
"""
This function plots an ellipse based on the given parameters.
Parameters
----------
x : (float) The x-coordinate of the center of the ellipse.
y : (float) The y-coordinate of the center of the ellipse.
a : (float) The length of the semi-major axis of the ellipse.
b : (float) The length of the semi-minor axis of the ellipse.
angle : (float) The rotation angle of the ellipse, in radians.
color : (str, optional) The color and line style of the ellipse plot, following matplotlib conventions. Defaults to "-r" (a red solid line).
ax : (matplotlib.axes.Axes, optional) The Axes object to draw the ellipse on. If None (default), a new figure and axes are created.
**kwargs: Additional keyword arguments to pass to plt.plot or ax.plot.
Returns
---------
None. This function plots the ellipse based on the specified parameters.
"""
t = np.arange(0, 2 * math.pi + 0.1, 0.1)
px = [a * math.cos(it) for it in t]
py = [b * math.sin(it) for it in t]
fx = rot_mat_2d(angle) @ (np.array([px, py]))
px = np.array(fx[0, :] + x).flatten()
py = np.array(fx[1, :] + y).flatten()
if ax is None:
plt.plot(px, py, color, **kwargs)
else:
ax.plot(px, py, color, **kwargs)
def plot_arrow(x, y, yaw, arrow_length=1.0,
origin_point_plot_style="xr",
head_width=0.1, fc="r", ec="k", **kwargs):
"""
Plot an arrow or arrows based on 2D state (x, y, yaw)
All optional settings of matplotlib.pyplot.arrow can be used.
- matplotlib.pyplot.arrow:
https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.arrow.html
Parameters
----------
x : a float or array_like
a value or a list of arrow origin x position.
y : a float or array_like
a value or a list of arrow origin y position.
yaw : a float or array_like
a value or a list of arrow yaw angle (orientation).
arrow_length : a float (optional)
arrow length. default is 1.0
origin_point_plot_style : str (optional)
origin point plot style. If None, not plotting.
head_width : a float (optional)
arrow head width. default is 0.1
fc : string (optional)
face color
ec : string (optional)
edge color
"""
if not isinstance(x, float):
for (i_x, i_y, i_yaw) in zip(x, y, yaw):
plot_arrow(i_x, i_y, i_yaw, head_width=head_width,
fc=fc, ec=ec, **kwargs)
else:
plt.arrow(x, y,
arrow_length * math.cos(yaw),
arrow_length * math.sin(yaw),
head_width=head_width,
fc=fc, ec=ec,
**kwargs)
if origin_point_plot_style is not None:
plt.plot(x, y, origin_point_plot_style)
def plot_curvature(x_list, y_list, heading_list, curvature,
k=0.01, c="-c", label="Curvature"):
"""
Plot curvature on 2D path. This plot is a line from the original path,
the lateral distance from the original path shows curvature magnitude.
Left turning shows right side plot, right turning shows left side plot.
For straight path, the curvature plot will be on the path, because
curvature is 0 on the straight path.
Parameters
----------
x_list : array_like
x position list of the path
y_list : array_like
y position list of the path
heading_list : array_like
heading list of the path
curvature : array_like
curvature list of the path
k : float
curvature scale factor to calculate distance from the original path
c : string
color of the plot
label : string
label of the plot
"""
cx = [x + d * k * np.cos(yaw - np.pi / 2.0) for x, y, yaw, d in
zip(x_list, y_list, heading_list, curvature)]
cy = [y + d * k * np.sin(yaw - np.pi / 2.0) for x, y, yaw, d in
zip(x_list, y_list, heading_list, curvature)]
plt.plot(cx, cy, c, label=label)
for ix, iy, icx, icy in zip(x_list, y_list, cx, cy):
plt.plot([ix, icx], [iy, icy], c)
class Arrow3D(FancyArrowPatch):
def __init__(self, x, y, z, dx, dy, dz, *args, **kwargs):
super().__init__((0, 0), (0, 0), *args, **kwargs)
self._xyz = (x, y, z)
self._dxdydz = (dx, dy, dz)
def draw(self, renderer):
x1, y1, z1 = self._xyz
dx, dy, dz = self._dxdydz
x2, y2, z2 = (x1 + dx, y1 + dy, z1 + dz)
xs, ys, zs = proj_transform((x1, x2), (y1, y2), (z1, z2), self.axes.M)
self.set_positions((xs[0], ys[0]), (xs[1], ys[1]))
super().draw(renderer)
def do_3d_projection(self, renderer=None):
x1, y1, z1 = self._xyz
dx, dy, dz = self._dxdydz
x2, y2, z2 = (x1 + dx, y1 + dy, z1 + dz)
xs, ys, zs = proj_transform((x1, x2), (y1, y2), (z1, z2), self.axes.M)
self.set_positions((xs[0], ys[0]), (xs[1], ys[1]))
return np.min(zs)
def _arrow3D(ax, x, y, z, dx, dy, dz, *args, **kwargs):
'''Add an 3d arrow to an `Axes3D` instance.'''
arrow = Arrow3D(x, y, z, dx, dy, dz, *args, **kwargs)
ax.add_artist(arrow)
def plot_3d_vector_arrow(ax, p1, p2):
setattr(Axes3D, 'arrow3D', _arrow3D)
ax.arrow3D(p1[0], p1[1], p1[2],
p2[0]-p1[0], p2[1]-p1[1], p2[2]-p1[2],
mutation_scale=20,
arrowstyle="-|>",
)
def plot_triangle(p1, p2, p3, ax):
ax.add_collection3d(art3d.Poly3DCollection([[p1, p2, p3]], color='b'))
def set_equal_3d_axis(ax, x_lims, y_lims, z_lims):
"""Helper function to set equal axis
Args:
ax (Axes3DSubplot): matplotlib 3D axis, created by
`ax = fig.add_subplot(projection='3d')`
x_lims (np.array): array containing min and max value of x
y_lims (np.array): array containing min and max value of y
z_lims (np.array): array containing min and max value of z
"""
x_lims = np.asarray(x_lims)
y_lims = np.asarray(y_lims)
z_lims = np.asarray(z_lims)
# compute max required range
max_range = np.array([x_lims.max() - x_lims.min(),
y_lims.max() - y_lims.min(),
z_lims.max() - z_lims.min()]).max() / 2.0
# compute mid-point along each axis
mid_x = (x_lims.max() + x_lims.min()) * 0.5
mid_y = (y_lims.max() + y_lims.min()) * 0.5
mid_z = (z_lims.max() + z_lims.min()) * 0.5
# set limits to axis
ax.set_xlim(mid_x - max_range, mid_x + max_range)
ax.set_ylim(mid_y - max_range, mid_y + max_range)
ax.set_zlim(mid_z - max_range, mid_z + max_range)
if __name__ == '__main__':
plot_ellipse(0, 0, 1, 2, np.deg2rad(15))
plt.axis('equal')
plt.show()
Loading...
举报
举报成功
我们将于2个工作日内通过站内信反馈结果给你!
请认真填写举报原因,尽可能描述详细。
请选择举报类型
取消
发送
误判申诉

此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。

如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。

取消
提交

简介

PythonRobotics 是用 Python 实现的机器人算法案例集合,该库包括了机器人设计中常用的定位算法、测绘算法、路径规划算法、SLAM、路径跟踪算法
取消

发行版

暂无发行版

贡献者

全部

近期动态

不能加载更多了
编辑仓库简介
简介内容
主页
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/zerosl/PythonRobotics.git
git@gitee.com:zerosl/PythonRobotics.git
zerosl
PythonRobotics
PythonRobotics
master
点此查找更多帮助

搜索帮助

评论
仓库举报
回到顶部
登录提示
该操作需登录 Gitee 帐号,请先登录后再操作。
立即登录
没有帐号,去注册

AltStyle によって変換されたページ (->オリジナル) /