Equally spaced points in a circle
Show older comments
Hi everyone! I am trying to create a function that gets as inputs coordinates of two points with the first point being the center and the distance between the two points defining the radius of the circle. And get as an output the coordinates of equally spaces points along this circle. This is my function but it isn't giving me the correct result
function points = get_equally_spaced_points(x1, y1, x2, y2) % Calculate the distance between the two points
distance = sqrt((x2 - x1)^2 + (y2 - y1)^2);
% Calculate the angle between the x-axis and the line connecting the two points
angle = atan2(y2 - y1, x2 - x1);
% Calculate the angular separation between the points
angular_separation = 2 * pi / 3;
% Calculate the coordinates of the additional points
points = zeros(4, 2);
points(1, :) = [x1, y1];
points(2, :) = [x2, y2];
for i = 1:2
current_angle = angle + (i - 1) * angular_separation;
x = x1 + distance * cos(current_angle); y = y1 + distance * sin(current_angle);
points(i + 2, :) = [x, y];
end
end
Accepted Answer
More Answers (0)
Categories
Find more on 2-D and 3-D Plots 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!