-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdxf_marker.m
82 lines (75 loc) · 2.22 KB
/
dxf_marker.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
function FID = dxf_marker(FID, markertype, X, Y, Z, varargin)
%DXF_MARKER Draw a set of markers.
% DXF_MARKER(FID, markertype, X, Y, Z) writes markers into DXF file.
% FID is a valid DXFLIB structure created with DXF_OPEN routine.
% markertype is a valid marker type of the following type:
% 'o' - circle,
% 'x' - x sign,
% '+' - plus sign,
% '^' - triangle.
% X, Y and Z are vectors or matrices of the same size containing
% coordinates of points in 3D space. The default size of marker is 1.
%
% DXF_MARKER(..., SIZE) allows to specify size of marker(s). If SIZE is
% a scalar, all markers have the same size according to the SIZE value
% specified. If SIZE is a matrix of size equal to X, Y or Z, each
% marker is rescaled according to corresponding SIZE value.
%
% See also DXF_POLYLINE, DXF_POINT, DXF_PRIMITIVE.
% Copyright 2008-2011 Grzegorz Kwiatek
% $Revision: 1.0.3 $ $Date: 2011.11.17 $
try
% align matrices
X=X(:);
Y=Y(:);
Z=Z(:);
if nargin == 5
SIZE = ones(size(X));
elseif nargin == 6
SIZE = varargin{1};
end
if isscalar(SIZE)
SIZE = SIZE * ones(size(X));
end
switch lower(markertype)
case 'o'
for i=1:length(X)
fprintf(FID.fid,'0\n');
fprintf(FID.fid,'CIRCLE\n');
dxf_print_layer(FID);
dxf_print_point(FID,0,X(i),Y(i),Z(i));
fprintf(FID.fid,'40\n');
fprintf(FID.fid,[sprintf('%d',SIZE(i)) '\n']);
end
case 'x'
a = sqrt(2);
for i=1:length(X)
XX = X(i) + [-a -a; a a]*SIZE(i)/2;
YY = Y(i) + [ a -a; -a a]*SIZE(i)/2;
ZZ = Z(i) + [0 0; 0 0];
dxf_polyline(FID, XX, YY, ZZ);
end
case '+'
for i=1:length(X)
a = SIZE(i) / 2 ;
XX = X(i) + [0 a; 0 -a];
YY = Y(i) + [-a 0; a 0];
ZZ = Z(i) + [0 0; 0 0];
dxf_polyline(FID, XX, YY, ZZ);
end
case '^'
for i=1:length(X)
h = sqrt(3) / 2 * SIZE(i);
a = SIZE(i);
XX = X(i) + [-0.5*a 0 0.5*a -0.5*a]';
YY = Y(i) + [-h/3 2*h/3 -h/3 -h/3]';
ZZ = Z(i) + [0 0 0 0]';
dxf_polyline(FID, XX, YY, ZZ);
end
end
catch exception
if FID.fid >= 0
fclose(FID.fid);
end
rethrow(exception);
end