-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplotting_minvo_curves
127 lines (112 loc) · 6.13 KB
/
plotting_minvo_curves
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
from time import time
import numpy as np
import random
from bsplinegenerator.bsplines import BsplineEvaluation
from bsplinegenerator.helper_functions import create_random_control_points_greater_than_angles
import matplotlib.pyplot as plt
### Control Points ###
# control_points = np.array([-3,-4,-2,-.5,1,0,2,3.5,3,6,8]) # 1 D
# control_points = np.array([[-3,-4,-2,-.5,1,0,2,3.5,3,5,6.5],
# [.5,3.5,6,5.5,3.7,2,-1,2,5,5.5,5]]) # 2 D
# control_points = np.array([[-3, -4, -2, -.5, 1 , 0, 2, 3.5, 3],
# [.5, 3.5, 6, 5.5, 3.7, 2, -1, 2, 5],
# [ 1, 3.2, 5, 0, 3.3, 1.5, -1, 2.5, 4]]) # 3D
# num_control_points = 10
# dimension = random.randint(1, 3)
# control_points = np.random.randint(10, size=(dimension,num_control_points)) # random
# control_points = create_random_control_points_greater_than_angles(num_control_points,order,1,dimension)
# control_points = np.array([[1.69984, 3.13518, 3.75944, 3.64158],
# [4.23739, 3.8813, 4.23739, 5.36086],
# [3,5,1,2]])
# control_points = np.array([[2, 2, 2, 7],
# [5, 5, 5, 8]])
# dimension = 3
scale_factor = 1.5
derivative_order = 0
order = 3
# control_points = np.array([[1, 4, 6],
# [3, 7, 1]])
# control_points = np.array([[1, 4, 6, 10],
# [3, 7, 1, 8]])
control_points = np.array([[2, 4, 6, 5],
[4, 12, 10, 4]])
# if len(control_points) == 1:
# control_points = control_points.flatten()
### Parameters
start_time = 0
# scale_factor = 1
# derivative_order = random.randint(1, order)
clamped = False
num_data_points_per_interval = 10000
### Create B-Spline Object ###
bspline = BsplineEvaluation(control_points, order, start_time, scale_factor, clamped)
# bspline.plot_spline(num_data_points_per_interval)
# for i in range(1,order):
# bspline.plot_derivative(num_data_points_per_interval, i)
#### Evaluate B-Spline Data ###
spline_data, time_data = bspline.get_spline_data(num_data_points_per_interval)
# spline_derivative_data, time_data = bspline.get_spline_derivative_data(num_data_points_per_interval,derivative_order)
# spline_derivative_magnitude_data, time_data = bspline.get_derivative_magnitude_data(num_data_points_per_interval,derivative_order)
# spline_curvature_data, time_data = bspline.get_spline_curvature_data(num_data_points_per_interval)
# angular_rate_data, time_data = bspline.get_angular_rate_data(num_data_points_per_interval)
# centripetal_acceleration_data, time_data = bspline.get_centripetal_acceleration_data(num_data_points_per_interval)
# basis_function_data, time_data = bspline.get_basis_function_data(num_data_points_per_interval)
# knot_points = bspline.get_knot_points()
# defined_knot_points = bspline.get_defined_knot_points()
# spline_at_knot_points = bspline.get_spline_at_knot_points()
# bezier_control_points = bspline.get_bezier_control_points()
minvo_control_points = bspline.get_minvo_control_points()
# print("bspline_control_points:")
# print(control_points)
# print("bezier_control_points:")
# print(bezier_control_points)
# print("order: " , order)
# print("control points: " , control_points)
# print("knot_points: " , knot_points)
# print("defined knot points: " , defined_knot_points)
# print("spline at knots: " , spline_at_knot_points)
# print("bezier_control_points: " , np.round(bezier_control_points,1))
# print("max_derivative_magnitude: " , np.max(spline_derivative_magnitude_data))
# print("max_curvature: " , np.max(spline_curvature_data))
# print("max_angular_rate: " , np.max(angular_rate_data))
# print("max_centripetal_acceleration: " , np.max(centripetal_acceleration_data))
# print("number_of_basis_functions: " , len(basis_function_data))
# centripetal_acceleration_data, time_data = bspline.get_centripetal_acceleration_data(num_data_points_per_interval)
# velocity_data, time_data = bspline.get_spline_derivative_data(num_data_points_per_interval,1)
# acceleration_data, time_data = bspline.get_spline_derivative_data(num_data_points_per_interval,2)
# velocity_mag_data, time_data = bspline.get_derivative_magnitude_data(num_data_points_per_interval, 1)
# accel_mag_data, time_data = bspline.get_derivative_magnitude_data(num_data_points_per_interval, 2)
# cross_term_data, time_data = bspline.get_cross_term_data(num_data_points_per_interval)
# print("min vel: " , np.min(velocity_mag_data))
# print("max accel: " , np.max(accel_mag_data))
# print("max cross_term: ", np.max(cross_term_data))
# index = np.argmax(cross_term_data)
# print("time at max cross: " , time_data[index])
##### Plot Spline Data
# bspline.plot_spline(num_data_points_per_interval)
# bspline.plot_spline_vs_time(num_data_points_per_interval)
# bspline.plot_basis_functions(num_data_points_per_interval)
# bspline.plot_derivative(num_data_points_per_interval, derivative_order)
# bspline.plot_derivative_vs_time(num_data_points_per_interval, derivative_order)
# bspline.plot_derivative_magnitude(num_data_points_per_interval, derivative_order)
# bspline.plot_derivative_magnitude(num_data_points_per_interval, 2)
# bspline.plot_curvature(num_data_points_per_interval)
# bspline.plot_angular_rate(num_data_points_per_interval)
# cross_term_data, time_data = bspline.get_cross_term_data(num_data_points_per_interval)
# bspline.plot_centripetal_acceleration(num_data_points_per_interval)
# bspline.plot_bezier_curves(num_data_points_per_interval)
# bspline.plot_minvo_curves(num_data_points_per_interval)
# plt.figure()
# plt.plot(time_data,cross_term_data)
# plt.title("cross term")
# plt.show()
# bspline.plot_centripetal_acceleration(num_data_points_per_interval)
# bspline.plot_angular_rate(num_data_points_per_interval)
plt.figure()
plt.plot(spline_data[0,:], spline_data[1,:], label="spline", color ="tab:blue", linewidth=2)
plt.scatter(minvo_control_points[0,:], minvo_control_points[1,:], label="minvo ctrl pts", color="tab:red")
plt.scatter(control_points[0,:], control_points[1,:], label="bspline ctrl pts", color="tab:orange")
plt.plot(minvo_control_points[0,:], minvo_control_points[1,:], color="tab:red")
plt.plot(control_points[0,:], control_points[1,:], color="tab:orange")
plt.legend()
plt.show()