-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdrawLineShapes.m
137 lines (124 loc) · 3.55 KB
/
drawLineShapes.m
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
function [th1,th2,th3,th4,th5] = drawLineShapes( x0,y0,z0,x1,y1,z1,T,divisions )
syms x y z
xflag = false;
yflag = false;
zflag = false;
if((x1-x0)==0)
xflag = true;
end
if((y1-y0)==0)
yflag = true;
end
if((z1-z0)==0)
zflag = true;
end
if(~xflag)
eqn(1) = (x-x0)/(x1-x0);
end
if(~yflag)
eqn(2) = (y-y0)/(y1-y0);
end
if(~zflag)
eqn(3) = (z-z0)/(z1-z0);
end
%check for the largest difference
if(abs(x0-x1) >= abs(y0-y1))
if(abs(x0-x1) >= abs(z0-z1))
largest = 'x';
else
largest = 'z';
end
else
if(abs(y0-y1) >= abs(z0-z1))
largest = 'y';
else
largest = 'z';
end
end
%calculate step
if(largest == 'x')
step = (x1-x0)/divisions;
elseif(largest == 'y')
step = (y1-y0)/divisions;
else
step = (z1-z0)/divisions;
end
%get the points on the line based on step
for i=1:divisions+1
if(largest == 'x')
xVec(i) = x0 + step*(i-1);
x = xVec(i);
if(~yflag && ~zflag)
[soly,solz]=solve(eqn(2)==subs(eqn(1)),eqn(3)==subs(eqn(1)));
yVec(i) = soly;
zVec(i) = solz;
elseif(yflag && ~zflag)
[solz]=solve(eqn(3)==subs(eqn(1)));
yVec(i) = y0;
zVec(i) = solz;
elseif(~yflag && zflag)
[soly]=solve(eqn(2)==subs(eqn(1)));
yVec(i) = soly;
zVec(i) = z0;
else
yVec(i) = y0;
zVec(i) = z0;
end
elseif(largest == 'y')
yVec(i) = y0 + step*(i-1);
y = yVec(i);
if(~xflag && ~zflag)
[solx,solz]=solve(eqn(1)==subs(eqn(2)),eqn(3)==subs(eqn(2)));
xVec(i) = solx;
zVec(i) = solz;
elseif(xflag && ~zflag)
[solz]=solve(eqn(3)==subs(eqn(2)));
xVec(i) = x0;
zVec(i) = solz;
elseif(~xflag && zflag)
[solx]=solve(eqn(1)==subs(eqn(2)));
xVec(i) = solx;
zVec(i) = z0;
else
xVec(i) = x0;
zVec(i) = z0;
end
else
zVec(i) = z0 + step*(i-1);
z = zVec(i);
if(~xflag && ~yflag)
[solx,soly]=solve(eqn(1)==subs(eqn(3)),eqn(2)==subs(eqn(3)));
xVec(i) = solx;
yVec(i) = soly;
elseif(xflag && ~yflag)
[soly]=solve(eqn(2)==subs(eqn(3)));
xVec(i) = x0;
yVec(i) = soly;
elseif(~xflag && yflag)
[solx]=solve(eqn(1)==subs(eqn(3)));
xVec(i) = solx;
yVec(i) = y0;
else
xVec(i) = x0;
yVec(i) = y0;
end
end
end
%initial position
s = invKinematics(double(xVec(1)),double(yVec(1)),double(zVec(1)),T,[0 0 0])
th1(1) = s(1);
th2(1) = s(2);
th3(1) = s(3);
th4(1) = s(4);
th5(1) = s(5);
%get theta vectors
for i=2:divisions+1
[double(xVec(i)) double(yVec(i)) double(zVec(i))]
s = invKinematics(double(xVec(i)),double(yVec(i)),double(zVec(i)),T,[th2(i-1) th3(i-1) th4(i-1)])
th1(i) = s(1);
th2(i) = s(2);
th3(i) = s(3);
th4(i) = s(4);
th5(i) = s(5);
end
end