mirror of https://gitlab.com/pamhyr/pamhyr2
add a Script directory for usefull scripts
parent
11906efb2c
commit
5f34cab682
|
|
@ -0,0 +1,52 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
# a lancer depuis src
|
||||||
|
import sys
|
||||||
|
from matplotlib import pyplot as plt
|
||||||
|
from Model.Geometry.Reach import Reach
|
||||||
|
from numpy import mean
|
||||||
|
|
||||||
|
def set_axes_equal(ax):
|
||||||
|
'''Make axes of 3D plot have equal scale so that spheres appear as spheres,
|
||||||
|
cubes as cubes, etc.. This is one possible solution to Matplotlib's
|
||||||
|
ax.set_aspect('equal') and ax.axis('equal') not working for 3D.
|
||||||
|
|
||||||
|
Input
|
||||||
|
ax: a matplotlib axis, e.g., as output from plt.gca().
|
||||||
|
'''
|
||||||
|
|
||||||
|
x_limits = ax.get_xlim3d()
|
||||||
|
y_limits = ax.get_ylim3d()
|
||||||
|
z_limits = ax.get_zlim3d()
|
||||||
|
|
||||||
|
x_range = abs(x_limits[1] - x_limits[0])
|
||||||
|
x_middle = mean(x_limits)
|
||||||
|
y_range = abs(y_limits[1] - y_limits[0])
|
||||||
|
y_middle = mean(y_limits)
|
||||||
|
z_range = abs(z_limits[1] - z_limits[0])
|
||||||
|
z_middle = mean(z_limits)
|
||||||
|
|
||||||
|
# The plot bounding box is a sphere in the sense of the infinity
|
||||||
|
# norm, hence I call half the max range the plot radius.
|
||||||
|
plot_radius = 0.5*max([x_range, y_range, z_range])
|
||||||
|
|
||||||
|
ax.set_xlim3d([x_middle - plot_radius, x_middle + plot_radius])
|
||||||
|
ax.set_ylim3d([y_middle - plot_radius, y_middle + plot_radius])
|
||||||
|
ax.set_zlim3d([z_middle - plot_radius, z_middle + plot_radius])
|
||||||
|
|
||||||
|
st_file = sys.argv[1]
|
||||||
|
my_reach = Reach(None)
|
||||||
|
my_reach.import_geometry(st_file)
|
||||||
|
my_reach.compute_guidelines()
|
||||||
|
|
||||||
|
ax = plt.figure().add_subplot(projection="3d")
|
||||||
|
for x, y, z in zip(my_reach.get_x(), my_reach.get_y(), my_reach.get_z()):
|
||||||
|
ax.plot(x, y, z, color='r', lw=1.)
|
||||||
|
for x, y, z in zip(my_reach.get_guidelines_x(), my_reach.get_guidelines_y(), my_reach.get_guidelines_z()):
|
||||||
|
ax.plot(x, y, z, color='b', lw=1.)
|
||||||
|
ax.set_xlabel('X')
|
||||||
|
ax.set_ylabel('Y')
|
||||||
|
ax.set_zlabel('Z')
|
||||||
|
plt.tight_layout()
|
||||||
|
set_axes_equal(ax)
|
||||||
|
plt.show()
|
||||||
Loading…
Reference in New Issue