-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
scadLinearExtrude.m
68 lines (67 loc) · 2.29 KB
/
scadLinearExtrude.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
function object = scadLinearExtrude(height, object, varargin)
%scadLinearExtrude - Linear Extrusion is a operation that takes a 2D object
%as input and generates a 3D object as a result.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% parameters:
%
% object - 2D scadStructure for extrudion
%
% height - distance
%
% center - if true, center placed in center of structure
%
% convexity - If the extrusion fails for a non-trival 2D shape, try
% setting the convexity parameter (the default is not 10, but 10 is a
% "good" value to try)
%
% twist - Twist is the number of degrees of through which the shape is
% extruded. Setting the parameter twist = 360 extrudes through one
% revolution. The twist direction follows the left hand rule.
%
% slices - defines the number of intermediate points along the Z axis of
% the extrusion
%
% scale - Scales the 2D shape by this value over the height of the
% extrusion. Scale can be a scalar or a vector 1 x 2
%
% fn - number of fragments
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
position = [];
param = '';
color = [];
while ~isempty(varargin)
switch lower(varargin{1})
case 'center'
param = [param ', center = ' boolean2string(varargin{2})];
case 'convexity'
param = [param ', convexity = ' num2str(varargin{2})];
case 'twist'
param = [param ', twist = ' num2str(varargin{2})];
case 'slices'
param = [param ', slices = ' num2str(varargin{2})];
case 'scale'
param = [param ', scale = [' strjoin(cellstr(num2str(varargin{2}(:))), ', ') ']' ];
case 'fn'
param = [param ', $fn = ' num2str(varargin{2})];
case 'position'
position = varargin{2};
case 'color'
color = varargin{2};
otherwise
error(['scadSquare: unknown paramiter - ' varargin{1}])
end
varargin(1:2) = [];
end
linear_extrude = ['linear_extrude(height = ' num2str(height) ...
param '){' ];
linear_extrude = [linear_extrude char(object.structure) newline];
linear_extrude = ([linear_extrude '}' ]);
object.structure = linear_extrude;
if ~isempty(position)
object = scadTranslate(position, object);
end
if ~isempty(color)
object = scadColor(color, object);
end
end