-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
scadSphere.m
62 lines (61 loc) · 1.67 KB
/
scadSphere.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
function object = scadSphere(diam, varargin)
%scadSphere - Creates a sphere at the origin of the coordinate system.
%%
%Parameters
% r Radius. This is the radius of the sphere. The resolution of the sphere
% is based on the size of the sphere and the $fa, $fs and $fn variables.
% For more information on these special variables look at:
% OpenSCAD_User_Manual/Other_Language_Features
% d
% Diameter. This is the diameter of the sphere.
% $fa
% Fragment angle in degrees
% $fs
% Fragment size in mm
% $fn
% Resolution
position = [];
color = [];
size = 'd';
param = '';
while ~isempty(varargin)
switch lower(varargin{1})
case 'fa'
param = [param ' $fa = ' num2str(varargin{2}) ','];
varargin(1:2) = [];
case 'fs'
param = [param ' $fs = ' num2str(varargin{2}) ','] ;
varargin(1:2) = [];
case 'fn'
param = [param ' $fn = ' num2str(varargin{2}) ','] ;
varargin(1:2) = [];
case 'position'
position = varargin{2};
varargin(1:2) = [];
case 'color'
color = varargin{2};
varargin(1:2) = [];
case 'r'
size = 'r';
varargin(1) = [];
case 'd'
size = 'd';
varargin(1) = [];
otherwise
error(['scadSphere: unknown paramiter - ' varargin{1}])
end
end
if ~isempty(param)
param = [', ' param];
param(end) = [];
end
sphere = (['sphere(' size '=' num2str(diam) param ')' ';' ]);
object = scadStructure();
object.structure = sphere;
if ~isempty(color)
object = scadColor(color, object);
end
if ~isempty(position)
object = scadTranslate(position, object);
end
end