render-generator-backend/test/lamp_shape_generation.py

44 lines
1.1 KiB
Python
Raw Normal View History

2017-10-25 08:48:13 +00:00
import numpy as np
import matplotlib.pyplot as plt
2017-10-25 09:19:55 +00:00
height = 3
2017-10-25 08:48:13 +00:00
radius = 2
base_radius = 0.5
2017-10-25 09:19:55 +00:00
base_length = 0.3
def morph_shape(x, L, H, morph_type="linear"):
y = np.ones(x.shape[0])
if morph_type == "linear":
y = (x/L)*H
elif morph_type == "logistic":
k = 10.0
v = 1.0
y = H/(1.0 + np.power(np.exp(-k*(x-L/4.0)), v))
elif morph_type == "sinusoid":
y = np.sin((x/L)*np.pi/2.0)
elif morph_type == "hyperbolic_tan":
y = np.tanh((x/L)*np.pi/2.0)
elif morph_type == "circle":
y = np.tanh((x/L)*np.pi/2.0)
return y
2017-10-25 08:48:13 +00:00
x_base = np.linspace(0, base_length, 10)
y_base = base_radius*np.ones(x_base.shape[0])
x_lamp = np.linspace(base_length, height, 100)
2017-10-25 09:19:55 +00:00
y_lamp = base_radius + morph_shape(x_lamp-base_length,
height-base_length,
radius-base_radius,
"hyperbolic_tan")
2017-10-25 08:48:13 +00:00
x = np.append(x_base, x_lamp)
y = np.append(y_base, y_lamp)
plt.plot(x, y)
axes = plt.gca()
axes.set_xlim([0, 1.1*base_length+height])
axes.set_ylim([0,1.1*radius])
2017-10-25 09:19:55 +00:00
plt.axis('equal')
2017-10-25 08:48:13 +00:00
plt.show()