-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsimulator_3d_engine.m
More file actions
106 lines (82 loc) · 1.81 KB
/
simulator_3d_engine.m
File metadata and controls
106 lines (82 loc) · 1.81 KB
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
%Simple 3D rotations and 2D projection
close all;
clear;
%Cube Definition in 3D
%Thing object center is origin and cube size is 1 unit
%Point list
object(1,:)=[ 0.5 0.5 0.5];
object(2,:)=[ 0.5 0.5 -0.5];
object(3,:)=[ 0.5 -0.5 0.5];
object(4,:)=[ 0.5 -0.5 -0.5];
object(5,:)=[-0.5 0.5 0.5];
object(6,:)=[-0.5 0.5 -0.5];
object(7,:)=[-0.5 -0.5 0.5];
object(8,:)=[-0.5 -0.5 -0.5];
%Point connections
edges=zeros(8,8);
edges(1,2)=1;
edges(1,3)=1;
edges(1,5)=1;
edges(2,1)=1;
edges(2,6)=1;
edges(2,4)=1;
edges(3,1)=1;
edges(3,4)=1;
edges(3,7)=1;
edges(4,8)=1;
edges(4,3)=1;
edges(4,2)=1;
edges(5,1)=1;
edges(5,1)=1;
edges(5,6)=1;
edges(5,7)=1;
edges(6,5)=1;
edges(6,2)=1;
edges(6,8)=1;
edges(7,3)=1;
edges(7,5)=1;
edges(7,8)=1;
edges(8,4)=1;
edges(8,6)=1;
edges(8,7)=1;
tethaX=pi/4;
Rx=[1 0 0; 0 cos(tethaX) -sin(tethaX); 0 sin(tethaX) cos(tethaX)];
tethaY=pi/3;
Ry=[cos(tethaY) 0 sin(tethaY); 0 1 0; -sin(tethaY) 0 cos(tethaY)];
tethaZ=pi/8;
Rz=[cos(tethaZ) -sin(tethaZ) 0; sin(tethaZ) cos(tethaZ) 0; 0 0 1];
for i=1:8
object(i,:)=(Rx*Ry*Rz*object(i,:)')';
end
figure;
for i=1:8
for j=(i+1):8
if i ~= j
if edges(i,j) == 1
pts = [object(i,:); object(j,:)];
line(pts(:,1), pts(:,2), pts(:,3));
end
end
end
end
xlim([-2 2]);
ylim([-2 2]);
zlim([-2 2]);
xlabel('WORLD COORDS');
figure;
for i=1:8
for j=(i+1):8
if i ~= j
if edges(i,j) == 1
%Projection pick x and y axis of world coordinates
p1=[object(i,1), object(j,1)];
p2=[object(i,2), object(j,2)];
line(p1,p2);
end
end
end
end
xlim([-2 2]);
ylim([-2 2]);
zlim([-2 2]);
xlabel('2D PROJECTED COORDS looking from Z');