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


hpp-fcl
Author(s):
autogenerated on Fri Jun 2 2023 02:39:01