-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplotcube.m
More file actions
73 lines (63 loc) · 1.7 KB
/
plotcube.m
File metadata and controls
73 lines (63 loc) · 1.7 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
function plotcube(axis, dimension, position, clr_c);
%% DESCRIPTON
%
% Function plots a defined cube into the selected axis
%
%% INPUTS
%
% axis... axis where you want the plot to appear
% dimension... length(x), width(y),height(z) of the cube
% position... position of the center of the cube
% clr_c... color of the cube
%
%% OUTPUT
%
% Plot of the cube on desired axis
%
%% VERSION
% Author: Neeraj Kulkarni
% Creation date: 01/08/2024
% Matlab version: matlab online
%
%% REVISION
%
% V1.0 | 01-Aug-2024 | Neeraj Kulkarni | Creation
%
%% PROGRAM
%
%% 1.) Definitions
% none needed
%
%% 2.) Computing
x_c(1) = -dimension(1)/2;
x_c(2) = dimension(1)/2;
x_c(3) = dimension(1)/2;
x_c(4) = -dimension(1)/2;
x_c(5) = -dimension(1)/2;
x_c(6) = dimension(1)/2;
x_c(7) = dimension(1)/2;
x_c(8) = -dimension(1)/2;
y_c(1) = dimension(2)/2;
y_c(2) = dimension(2)/2;
y_c(3) = -dimension(2)/2;
y_c(4) = -dimension(2)/2;
y_c(5) = dimension(2)/2;
y_c(6) = dimension(2)/2;
y_c(7) = -dimension(2)/2;
y_c(8) = -dimension(2)/2;
z_c(1) = -dimension(3)/2;
z_c(2) = -dimension(3)/2;
z_c(3) = -dimension(3)/2;
z_c(4) = -dimension(3)/2;
z_c(5) = dimension(3)/2;
z_c(6) = dimension(3)/2;
z_c(7) = dimension(3)/2;
z_c(8) = dimension(3)/2;
vertices_c = [x_c(1) y_c(1) z_c(1); x_c(2) y_c(2) z_c(2); x_c(3) y_c(3) z_c(3); x_c(4) y_c(4) z_c(4); x_c(5) y_c(5) z_c(5); x_c(6) y_c(6) z_c(6); x_c(7) y_c(7) z_c(7); x_c(8) y_c(8) z_c(8)];
faces_c = [4 3 2 1; 2 3 7 6; 3 4 8 7; 1 2 6 5; 2 3 7 6; 1 4 8 5];
%% 2.) -Translate Vertices
vertices_translated = [vertices_c(:,1)+position(1) vertices_c(:,2)+position(2) vertices_c(:,3)+position(3)];
%% 3.) Plot
patch(axis, 'Vertices', vertices_translated, 'Faces', faces_c, 'FaceColor', clr_c, 'EdgeColor', clr_c);
%%
end