MATLAB Examples

# Geometry Function for a Circle

This example shows how to write a geometry function for creating a circular region. Parametrize a circle with radius 1 centered at the origin (0,0), as follows:

A geometry function must have at least two segments. To satisfy this requirement, break up the circle into four segments.

Now that you have a parametrization, write the geometry function. Save this function file as circlefunction.m on your MATLAB® path. This geometry is simple to create because the parametrization does not change depending on the segment number.

function [x,y] = circlefunction(bs,s)
% Create a unit circle centered at (0,0) using four segments.
switch nargin
case 0
x = 4; % four edge segments
return
case 1
A = [0,pi/2,pi,3*pi/2; % start parameter values
pi/2,pi,3*pi/2,2*pi; % end parameter values
1,1,1,1; % region label to left
0,0,0,0]; % region label to right
x = A(:,bs); % return requested columns
return
case 2
x = cos(s);
y = sin(s);
end

Plot the geometry displaying the edge numbers and the face label.

pdegplot(@circlefunction,'EdgeLabels','on','FaceLabels','on') axis equal