generate_distance_plot.py
Go to the documentation of this file.
1 import matplotlib.pyplot as plt
2 import numpy as np
3 
4 interactive = False
5 
6 m = 1.0
7 b = 1.2
8 
9 mb = m + b
10 
11 X = np.array([-mb / 2, 0, m, mb, 2 * mb])
12 # X = np.linspace(-1, 4., 21)
13 
14 
15 def dlb(d):
16  if d < 0:
17  return None
18  if d > mb:
19  u = d - mb
20  return mb - m + u / 2
21  return d - m
22 
23 
24 plt.figure(figsize=(9, 3.5))
25 # plt.plot(X, X-m, ":k")
26 # plt.plot([m+b, X[-1]], [b, b], ":k")
27 plt.fill_between(
28  [m + b, X[-1]],
29  [b, b],
30  [b, X[-1] - m],
31  alpha=0.2,
32  hatch="|",
33  facecolor="g",
34  label="Distance lower band area",
35 )
36 plt.plot(X, [dlb(x) for x in X], "-g", label="distance lower bound")
37 # plt.plot([X[0], m, m, X[-1]], [0, 0, b, b], ":k")
38 plt.axvspan(X[0], m, alpha=0.5, hatch="\\", facecolor="r", label="Collision area")
39 
40 
41 ax = plt.gca()
42 ax.set_xlabel("Object distance")
43 ax.set_xticks([0, m, mb])
44 ax.set_xticklabels(["0", "security margin", "security margin\n+ break distance"])
45 ax.set_yticks([0, b])
46 ax.set_yticklabels(["0", "break distance"])
47 ax.grid(which="major", ls="solid")
48 ax.grid(which="minor", ls="dashed")
49 
50 plt.axvline(0, ls="solid")
51 # plt.axvline(m, ls="dashed", label="margin")
52 # plt.axvline(mb, ls="dashed")
53 plt.axhline(0.0, ls="solid")
54 
55 plt.title("Collision and distance lower band")
56 plt.legend(loc="lower right")
57 if interactive:
58  plt.show()
59 else:
60  import os.path as path
61 
62  dir_path = path.dirname(path.realpath(__file__))
63  plt.savefig(
64  path.join(dir_path, "distance_computation.png"),
65  bbox_inches="tight",
66  orientation="landscape",
67  )
generate_distance_plot.dlb
def dlb(d)
Definition: generate_distance_plot.py:15


hpp-fcl
Author(s):
autogenerated on Sat Nov 23 2024 03:44:58