Link:http://output.to/sideway/default.asp?qno=140600011 Matlab Code: dwlingeom
MatLab: Frequently Used Codes
Major Reference
Source: MatLab Verson 7.0
MatLab Package is designed for presentations, and therefore all data
stored in arrays can be presented graphically.
Simple Line Geometry of Cyclic Points
Points are
equally spaced in the form of a circle can be used to plot some simple line
geometry by joining data points with lines.
dwlingeom
Code:
function varargout=dwlingeom(varargin)
%dwlingeom plots 2D line polygon
%
% dwlingeom
% to plot a 100-sided line polygon with circumcircle centre at [0,0] and radius
of circumcircle equals to 1.
%
% varargout: ([],[a],[b],[c])
%
% varargint: ([a],[b],[c],[d])
%
% dwlingeom(n)
% for n=1, one single point is plotted
at y equals to 0 and x equals to 0 plus offset radius 1 based on circumcircle
centre at [0,0].
% for n=2, a line is plotted parallel to x-axis at y equals to 0 and x equals to
0 plus offset radius 1 based on circumcircle centre at [0,0].
% for n>=3, a line polygon of n sides is plotted.
% to plot a n-sided line polygon with circumcircle centre at [0,0] and radius of
circumcircle equals to 1.
%
% dwlingeom(n,r)
% to plot a n-sided line polygon with circumcircle centre at [0,0] and radius of
circumcircle equals to r.
%
% dwlingeom(n,r,x)
% to plot a n-sided line polygon with circumcircle centre at [x,0] and radius of
circumcircle equals to r.
%
% dwlingeom(n,r,x,y)
% to plot a n-sided line polygon with circumcircle centre at [x,y] and radius of
circumcircle equals to r.
%
% ---------
% Copyright (c) 2014, All Right Reserved, http://sideway.hk/
% LastChanged:20/06/2014
% version:000.00001 created 20/06/2014 from sideway.hk
%
%
if nargin==0
n=100;r=1;x=0;y=0;
elseif nargin==1
n=varargin{1};r=1;x=0;y=0;
elseif nargin==2
n=varargin{1};r=varargin{2};x=0;y=0;
elseif nargin==3
n=varargin{1};r=varargin{2};x=varargin{3};y=0;
elseif nargin==4
n=varargin{1};r=varargin{2};x=varargin{3};y=varargin{4};
else
error('in argument more than four');
end
[a,b]=dwcirspace(n,r,x,y);
if nargout==0
plot(a,b);
elseif nargout==1
ha=plot(a,b);
varargout{1}=ha;
elseif nargout==2
ha=plot(a,b);
varargout{1}=ha;
varargout{2}=[a,b];
elseif nargout==3
ha=plot(a,b);
varargout{1}=ha;
varargout{2}=a;
varargout{3}=b;
else
error('out argument more than three');
end
Example
-
Use function
dwlingeom with default value to generate a line 100-sided polygon with
circumcircle centre at [0,0] and radius of circumcircle equals to 1.
-
Use function dwlingeom with n=5 to generate a line regular pentagon with
circumcircle centre at [0,0] and radius of circumcircle equals to 1.
-
Use function dwlingeom with n=3 to generate a line equilateral triangle with
circumcircle centre at [0,0] and radius of circumcircle equals to 5.
-
Use function dwlingeom with n=2 to generate a line with
circumcircle centre at [0,0] and radius of circumcircle equals to 5, i.e. a line
from [5,0] to [-5,0].
-
Use function dwlingeom with n=1 to
plot a point at circle centre [4,5] with circle radius r equal to 2, i.e. a
point at [6,5].
-
Link:http://output.to/sideway/default.asp?qno=140600010 Matlab Code: dwcirspace
MatLab: Frequently Used Codes
Major Reference
Source: MatLab Verson 7.0
MatLab Package is designed for array or matrix operations, and therefore all data are
stored in the form of arrays.
Array of Cyclic Points
Circular spaced points is one of the common used form of points. Points are
equally spaced in the form of a circle.
dwcirspace
Code:
function varargout=dwcirspace(varargin)
%dwcirspace creates a matrix of cyclic or circular spaced points
%
%varargout:
(a,[b])
%
%varargint:
([a],[b],[c],[d])
%
% dwcirspace
% construct an 2x101 matrix of 101 circular spaced points with
circumcircle centre at
[0,0] and circumcircle radius equals to 1.
%
% dwcirspace(n)
% for n=1 an 2x1
vector of a single point is created at y equals to 0 and x equals to 0 plus
offset radius 1 based on circumcircle centre at [0,0].
% for n=2 an 2x2 matrix of two points for a line is created parallel to x-axis
at y equals to 0 and x equals to 0 plus offset radius 1 based on circumcircle
centre at [0,0].
% for n>=3 an 2xn+1 matrix of n+1 circular spaced points is created
% construct an 2xn+1 matrix of n+1 circular spaced points with
circumcircle centre at
[0,0] and circumcircle radius equals to 1.
%
% dwcirspace(n,r)
% construct an 2xn+1 matrix of n+1 circular spaced points with
circumcircle centre at
[0,0] and circumcircle radius equals to r.
%
% dwcirspace(n,r,x)
% construct an 2xn+1 matrix of n+1 circular spaced points with
circumcircle centre at
[x,0] and circumcircle radius equals to r.
%
% dwcirspace(n,r,x,y)
% construct an 2xn+1 matrix of n+1 circular spaced points with
circumcircle centre at
[x,y] and circumcircle radius equals to r.
%
% ---------
%
Copyright (c) 2014, All Right Reserved, http://sideway.hk/
% LastChanged:20/06/2014
% version:000.00001 created 20/06/2014 from sideway.hk
%
%
if nargin==0
n=100;r=1;x=0;y=0;
elseif nargin==1
n=varargin{1};r=1;x=0;y=0;
elseif nargin==2
n=varargin{1};r=varargin{2};x=0;y=0;
elseif nargin==3
n=varargin{1};r=varargin{2};x=varargin{3};y=0;
elseif nargin==4
n=varargin{1};r=varargin{2};x=varargin{3};y=varargin{4};
else
error('in argument more than four');
end
if n<=0
error('number of point must be greater than zero');
end
th=(0:1/n:1)*2*pi;
xunit=r*cos(th)+x;
yunit=r*sin(th)+y;
if n==1
xunit(2)=[];
yunit(2)=[];
elseif n==2
xunit(3)=[];
yunit(3)=[];
end
if nargout==0
error('out argument
less than one');
elseif nargout==1
vrargout{1}=[xunit; yunit];
elseif nargout==2
varargout{1}=xunit;
varargout{2}=yunit;
else
error('out argument more than two');
end
Example
-
Use function
dwcirspace with default value to generate a 2x11 matrix
-
Use function
dwcirspace with default value to generate two 1x11 vectors
-
Use function dwcirspace with repeating number n equals to 5 and radius r equals
to 2 to generate two 1x6 vectors
-
|
|