generated from hariharan382/blog
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdh.py
170 lines (138 loc) · 4.11 KB
/
dh.py
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
import matplotlib.pyplot as plt
import numpy as np
import mpl_toolkits.mplot3d
from math import sin, cos
import math
l = 8
b = 4
limit=10
fig = plt.figure()
ax=fig.add_subplot(111,projection='3d')
ax.set_xlim(-limit,limit)
ax.set_ylim(-limit,limit)
ax.set_zlim(-limit,limit)
ax.set_xlabel('"X')
ax.set_ylabel("Y")
ax.set_zlabel("Z")
o=np.matrix([[0,0,0,1]])
FR = np.matrix([[1, 0, 0, l / 2],
[0, 0, 0, b / 2],
[0, 0, 0, 0],
[0, 0, 0, 1]])
bl = np.matrix([[1, 0, 0, -l / 2],
[0, 1, 0, -b / 2],
[0, 0, 1, 0],
[0, 0, 0, 1]])
br = np.matrix([[1, 0, 0, l / 2],
[0, 0, 0, -b / 2],
[0, 0, 0, 0],
[0, 0, 0, 1]])
fl = np.matrix([[1, 0, 0, -l / 2],
[0, 1, 0, b / 2],
[0, 0, 1, 0],
[0, 0, 0, 1]])
T = np.matrix([[1, 0, 0, 3],
[0, 1, 0, 3],
[0, 0, 1, 0],
[0, 0, 0, 1]])
def dh(q, a, d, t):
z = np.matrix([[np.cos(math.radians(t)), -np.sin(math.radians(t)), 0, q],
[np.sin(math.radians(t)) * np.cos(math.radians(a)), np.cos(math.radians(t)) * np.cos(math.radians(a)),
-np.sin(math.radians(a)), -d * np.sin(math.radians(a))],
[np.sin(math.radians(t)) * np.sin(math.radians(a)), np.cos(math.radians(t)) * np.sin(math.radians(a)),
np.cos(math.radians(a)), d * np.cos(math.radians(a))],
[0, 0, 0, 1]])
return z
def point(x):
ax.scatter(df.item(0),df.item(1),df.item(2),cmap='Greens')
return df
"""def lin_plot(x,y):
a=point(x)
b=point(y)
plt.plot([a.item(0),b.item(0)],[a.item(1),b.item(1)],[a.item(2),b.item(2)],linewidth=0.5)
lin_plot(FR,fl)
lin_plot(fl,bl)
lin_plot(br,FR)
lin_plot(br,bl)"""
def rotx(alpha):
"""
Create a 3x3 rotation matrix about the x axis
"""
rx = np.array([[1, 0, 0, 0 ],
[0, cos(alpha), -sin(alpha),0],
[0, sin(alpha), cos(alpha),0 ],
[0,0,0,1]])
return rx
def roty(beta):
"""
Create a 3x3 rotation matrix about the y axis
"""
ry = np.array([[cos(beta), 0, sin(beta),0],
[0, 1, 0 ,0],
[-sin(beta), 0, cos(beta),0],
[0,0,0,1]])
return ry
def rotz(gamma):
"""
Create a 3x3 rotation matrix about the z axis
"""
rz = np.array([[cos(gamma), -sin(gamma), 0,0],
[sin(gamma), cos(gamma), 0,0],
[0, 0, 1,0],
[0,0,0,1]])
return rz
def rotxyz(alpha, beta, gamma):
"""
Create a 3x3 rotation matrix about the x,y,z axes
"""
return rotx(alpha).dot(roty(beta)).dot(rotz(gamma))
l1=2
l2=4
l3=4
q=rotxyz(0,3.14/2,0)
"""
q=rotxyz(3.14/2,0,0)
print(q)
print("------")"""
theta1=0
theta2=45
tehta3=90
fg=dh(0,theta1,0,0)
print(fg)
b=dh(l2,0,0,90)
c=dh(l3,0,0,45)
def lin_plot(x,y):
a=x
b=y
plt.plot([a.item(0),b.item(0)],[a.item(1),b.item(1)],[a.item(2),b.item(2)],linewidth=0.5)
for i in range(1):
fg=dh(0,theta1,0,0)
a = dh(0, -90, 2, 45)
print("==============")
print(fg)
print("//////////////////////////////////----------->")
print([email protected](o))
print("-------")
z = point(fg)
print("88888888888888888888888888")
print(z)
print("]]]]]]]]]]]")
print(lin_plot(o, z))
print("----------")
lin_plot(o,point(fg))
lin_plot(point(fg),point(fg @ a))
lin_plot(point(fg@a),point(fg @ a @ b))
lin_plot(point(fg @ a @ b),point(fg @ a @ b @ c))
h=fg @ a @ b @ c
print(np.around(h))
print(h.item(3))
print(h.item(7))
print((h.item(11)))
"""for i in range(4):
a = dh(0, -90, 2, i*20)
print(np.round(point(a), 2))
print(point(a @ b))
print(point(a @ b @ c))"""
ax.scatter(0,2,-6,cmap='Greens',linewidths=10)
plt.show()