Fixing my code to get proper output.
3 views (last 30 days)
Show older comments
Hello All,
Please note I need to construct Delaunays disc in matlab. I tried to do it in following way but its not working properly. Can someone help me in fixing this code? Any help will be greatly appreciated. You are free to take any value of n, it doesnt matter. :) :P
% Script for delaunay's disc
clc
close all
figure
axis equal off
hold on
n=50; % Declaring the value of n
% Calculation of concentric circles
x = linspace(0,n,1000);
y1 = sqrt(n^2-x.^2); % Calculation of circle equation for the top circle
y2 = -y1; % Constructing the Bottom circle
fill([x 0],[y1 0],rand(1,3)) % Filling the top circle with red color
fill([x 0],[y2 0],rand(1,3))
for k=n:-1:1
x=linspace(-k,k,1000);
y1 = sqrt(k^2-x.^2);
y2= -y1;
if(mod(k,2)==0)
fill(x,y1,rand(1,3))
fill(x,y2,rand(1,3))
else
fill(x,y1,rand(1,3))
fill(x,y2,rand(1,3))
end
end
title('Delaunays disc')
hold off
shg
Below is the output I am getting when I am running this code.

However, I am supposed to get below output:

Please help me out with this.
0 Comments
Answers (1)
BhaTTa
on 29 May 2025
% Script for a custom "Delaunay-like" disc with quadrant coloring
clc % Clear the command window
close all % Close all open figures
figure % Create a new figure
axis equal off % Set equal aspect ratio and turn off axes ticks/labels
hold on % Hold the current plot so we can draw multiple shapes
n = 50; % Declaring the value of n (outermost radius)
% Define a high number of points for smooth arcs
num_points_per_quad = 100;
% Loop from the largest radius (n) down to 1
for k = n:-1:1
% --- Define Angles for Each Quadrant ---
theta_q1 = linspace(0, pi/2, num_points_per_quad); % Q1: 0 to 90 degrees
theta_q2 = linspace(pi/2, pi, num_points_per_quad); % Q2: 90 to 180 degrees
theta_q3 = linspace(pi, 3*pi/2, num_points_per_quad); % Q3: 180 to 270 degrees
theta_q4 = linspace(3*pi/2, 2*pi, num_points_per_quad); % Q4: 270 to 360 degrees
% --- Generate Coordinates for Each Quadrant's Arc ---
x_q1_arc = k * cos(theta_q1);
y_q1_arc = k * sin(theta_q1);
x_q2_arc = k * cos(theta_q2);
y_q2_arc = k * sin(theta_q2);
x_q3_arc = k * cos(theta_q3);
y_q3_arc = k * sin(theta_q3);
x_q4_arc = k * cos(theta_q4);
y_q4_arc = k * sin(theta_q4);
% --- Fill Each Quadrant with a NEW Random Color ---
% For each fill, we create a closed polygon by combining the arc points with the origin (0,0)
% Quadrant 1 (Top-Right)
fill([x_q1_arc, 0], [y_q1_arc, 0], rand(1,3)); % rand(1,3) generates a new random color for R, G, B
% Quadrant 2 (Top-Left)
fill([x_q2_arc, 0], [y_q2_arc, 0], rand(1,3));
% Quadrant 3 (Bottom-Left)
fill([x_q3_arc, 0], [y_q3_arc, 0], rand(1,3));
% Quadrant 4 (Bottom-Right)
fill([x_q4_arc, 0], [y_q4_arc, 0], rand(1,3));
end
title('Delaunays Disc (Quadrant-Colored)'); % Updated title for clarity
hold off % Release the plot to prevent further additions
shg % Show the figure (bring to front)
0 Comments
See Also
Categories
Find more on Delaunay Triangulation in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!