-
Notifications
You must be signed in to change notification settings - Fork 0
/
testquart.m
149 lines (126 loc) · 3.5 KB
/
testquart.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
137
138
139
140
141
142
143
144
145
146
147
148
149
% Investigating 3d quaternion rotation
clear
clc
close all
%% View coordinates
a1 = [0 0 0];
a2 = [0 0 3];
r1= [a1(1) a2(1)];
r2= [a1(2) a2(2)];
r3= [a1(3) a2(3)];
%% Cube coordinates
p1 = [0 0 1.224745];
p2 = [1.154701 0 0.4082483];
p3 = [-0.5773503 1 0.4082483];
p4 = [-0.5773503 -1 0.4082483];
p5 = [0.5773503 1 -0.4082483];
p6 = [0.5773503 -1 -0.4082483];
p7 = [-1.154701 0 -0.4082483];
p8 = [0 0 -1.224745];
%% Plane formation
x = [p1(1) p2(1) p5(1) p3(1)]; %%done
y = [p1(2) p2(2) p5(2) p3(2)];
z = [p1(3) p2(3) p5(3) p3(3)];
x1 = [p1(1) p3(1) p7(1) p4(1)]; %%done
y1 = [p1(2) p3(2) p7(2) p4(2)];
z1 = [p1(3) p3(3) p7(3) p4(3)];
x2 = [p1(1) p4(1) p6(1) p2(1)]; %%done
y2 = [p1(2) p4(2) p6(2) p2(2)];
z2 = [p1(3) p4(3) p6(3) p2(3)];
x3 = [p2(1) p6(1) p8(1) p5(1)]; %%not done
y3 = [p2(2) p6(2) p8(2) p5(2)];
z3 = [p2(3) p6(3) p8(3) p5(3)];
x4 = [p3(1) p5(1) p8(1) p7(1)]; %%not done
y4 = [p3(2) p5(2) p8(2) p7(2)];
z4 = [p3(3) p5(3) p8(3) p7(3)];
x5 = [p4(1) p7(1) p8(1) p6(1)]; %%not done
y5 = [p4(2) p7(2) p8(2) p6(2)];
z5 = [p4(3) p7(3) p8(3) p6(3)];
%% Orientation of face
% %Centroid coordinates
ab = ((p4(1)+p7(1)+p8(1)+p6(1))/4);
ac = ((p4(2)+p7(2)+p8(2)+p6(2))/4);
ad = ((p4(3)+p7(3)+p8(3)+p6(3))/4);
V0 = [ab ac ad];
a2 = [0 0 3];
%% Formulation of quaternion
temp = cross(V0,a2);
theta = abs(asin(norm(cross(V0,a2))));
% a2L = sqrt(a2(1)^2+a2(2)^2+a2(3)^2);
% V0L = sqrt(V0(1)^2+V0(2)^2+V0(3)^2);
L = norm(cross(V0,a2));
M = cross(V0,a2);
Qxyz = (M)/(L);
Qw = [cos(theta/2)];
q = [Qw Qxyz];
n = quatnormalize(q)
q1 = quaternion(n)
%% Draw view vector
% figure
% grid on
% hold all
% g1 = [a1(1) Finalx];
% g2 = [a1(2) Finaly];
% g3 = [a1(3) Finalz];
% g1 = [a1(1) qXYZ(1)];
% g2 = [a1(2) qXYZ(2)];
% g3 = [a1(3) qXYZ(3)];
% plot3(g1,g2,g3)
%% Rotated coordinates
% q1 = quaternion(Finalw,Finalx,Finaly,Finalz)
% rt1 = 0.5*((p1tw-q1*p1tw*q1));
% rt2 = 0.5*((p2-q1*p2*q1));
% rt3 = 0.5*((p3-q1*p3*q1));
% rt4 = 0.5*((p4-q1*p4*q1));
% rt5 = 0.5*((p5-q1*p5*q1));
% rt6 = 0.5*((p6-q1*p6*q1));
% rt7 = 0.5*((p7-q1*p7*q1));
% rt8 = 0.5*((p8-q1*p8*q1));
rt1 = rotateframe(q1, p1)
rt2 = rotateframe(q1, p2)
rt3 = rotateframe(q1, p3)
rt4 = rotateframe(q1, p4)
rt5 = rotateframe(q1, p5)
rt6 = rotateframe(q1, p6)
rt7 = rotateframe(q1, p7)
rt8 = rotateframe(q1, p8)
xa = [rt1(1) rt2(1) rt5(1) rt3(1)];
ya = [rt1(2) rt2(2) rt5(2) rt3(2)];
za = [rt1(3) rt2(3) rt5(3) rt3(3)];
x1a = [rt1(1) rt3(1) rt7(1) rt4(1)];
y1a = [rt1(2) rt3(2) rt7(2) rt4(2)];
z1a = [rt1(3) rt3(3) rt7(3) rt4(3)];
x2a = [rt1(1) rt4(1) rt6(1) rt2(1)];
y2a = [rt1(2) rt4(2) rt6(2) rt2(2)];
z2a = [rt1(3) rt4(3) rt6(3) rt2(3)];
x3a = [rt2(1) rt6(1) rt8(1) rt5(1)];
y3a = [rt2(2) rt6(2) rt8(2) rt5(2)];
z3a = [rt2(3) rt6(3) rt8(3) rt5(3)];
x4a = [rt3(1) rt5(1) rt8(1) rt7(1)];
y4a = [rt3(2) rt5(2) rt8(2) rt7(2)];
z4a = [rt3(3) rt5(3) rt8(3) rt7(3)];
x5a = [rt4(1) rt7(1) rt8(1) rt6(1)];
y5a = [rt4(2) rt7(2) rt8(2) rt6(2)];
z5a = [rt4(3) rt7(3) rt8(3) rt6(3)];
%% Draw rotated and unrotated cube
figure
hold all
grid on
xlabel('x')
ylabel('y')
zlabel('z')
fill3(x,y,z,1);
fill3(x1,y1,z1,2);
fill3(x2,y2,z2,3);
fill3(x3,y3,z3,4);
fill3(x4,y4,z4,5);
fill3(x5,y5,z5,6);
figure
hold all
plot3(r1,r2,r3)
fill3(xa,ya,za,1);
fill3(x1a,y1a,z1a,2);
fill3(x2a,y2a,z2a,3);
fill3(x3a,y3a,z3a,4);
fill3(x4a,y4a,z4a,5);
fill3(x5a,y5a,z5a,6);