-2

I am trying to draw a shape using matlab. Here I need to join arcs. I created arc using following code

circr = @(radius,rad_ang)  [radius*cos(rad_ang);  radius*sin(rad_ang)];         % Circle Function For Angles In Radians

N = 25;                                                         % Number Of Points In Complete Circle

r_angl = linspace(pi/2, 5*pi/4, N);                             % Angle Defining Arc Segment (radians)

radius = 0.5;                                                   % Arc Radius
xy_r = circr(radius,r_angl);                                    % Matrix (2xN) Of (x,y) Coordinates

figure(1)
plot(xy_r(1,:), xy_r(2,:)) 

axis([-1.25*radius  1.25*radius    0  1.25*radius]) 

Code generates following output

Output Image

Now I modified code to draw other arc

circr = @(radius,rad_ang)  [radius*cos(rad_ang);  radius*sin(rad_ang)];         % Circle Function For Angles In Radians
N = 25;                                                         % Number Of Points In Complete Circle
r_angl = linspace(pi/2, 5*pi/4, N);                             % Angle Defining Arc Segment (radians)

radius = 0.5;                                                   % Arc Radius
xy_r = circr(radius,r_angl);                                    % Matrix (2xN) Of (x,y) Coordinates




r_angl1 = linspace(4*pi/4,pi/4);                             % Angle   Defining Arc Segment (radians)

radius1 = 0.1;                                                   % Arc Radius
xy_r1 = circr(radius1,r_angl1);                                    % Matrix (2xN) Of (x,y) Coordinates


figure(1)
plot(xy_r(1,:), xy_r(2,:),xy_r1(2,:),xy_r1(1,:))                                
axis([-1.25*radius  1.25*radius    0  1.25*radius])             % Set Axis Limits

axis equal 

This code generates Output 2

How can I join both arcs? I need to join them using their end points

swapnil gandhi
  • 816
  • 1
  • 20
  • 38

1 Answers1

-1

Inserting the following lines will joint the end points with lines

hold on;
line([xy_r(1,1) xy_r1(1,end)], [xy_r(2,1) xy_r1(2,end)]);
line([xy_r(1,end) xy_r1(2,1)], [xy_r(2,end) xy_r1(1,1)]);

Together:

figure(1)
plot(xy_r(1,:), xy_r(2,:),xy_r1(2,:),xy_r1(1,:))
hold on;
line([xy_r(1,1) xy_r1(1,end)], [xy_r(2,1) xy_r1(2,end)]);
line([xy_r(1,end) xy_r1(2,1)], [xy_r(2,end) xy_r1(1,1)]);

axis([-1.25*radius  1.25*radius    0  1.25*radius])   % Set Axis Limits
axis equal 

enter image description here

DMR
  • 1,479
  • 1
  • 8
  • 11