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:

$x = \cos \left( t \right),$ $y = \sin \left( t \right),$ $0 \le t \le 2 \pi.$

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

  • $0 \le t \le \pi/2$
  • $\pi/2 \le t \le \pi$
  • $\pi \le t \le 3 \pi/2$
  • $3 \pi/2 \le t \le 2 \pi$

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
    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
    case 2
        x = cos(s);
        y = sin(s);

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

axis equal