-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsphere.m
47 lines (40 loc) · 1.17 KB
/
sphere.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
classdef sphere
properties
center
radius
end
properties (GetAccess = private)
precision = 200;
end
properties (Dependent)
% structure: coordinates of sphere surface
S
end
methods
%function center = set
function S = get.S( obj )
S.x0 = zeros(1,1);
S.y0 = zeros(1,1);
S.z0 = zeros(1,1);
phi = 0.0;
i = 1;
while phi <= 2*pi
theta = -pi/2;
while theta <= pi/2
S.x0(i,1) = obj.center(1,1) + obj.radius * cos(theta) * cos(phi);
S.y0(i,1) = obj.center(1,2) + obj.radius * cos(theta) * sin(phi);
S.z0(i,1) = obj.center(1,3) + obj.radius * sin(theta);
theta = theta + pi/obj.precision;
i = i + 1;
end
phi = phi + pi/obj.precision;
end
end
function plot( obj, r0, R )
obj.center = r0;
obj.radius = R;
s = obj.S;
scatter3( s.x0,s.y0,s.z0, '.' );
end
end
end