![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/985935/image.png)
How to map a point inside a circle to circle area in MATLAB?
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Hi I have a point inside a circle in MATLAB. I want to map it to circle environment. I did this but it is not always useful!
function [xr,yr] = FindSurroundingPoint(xc,yc,x2,y2,r)
x=x2-xc;
y=y2-yc;
angle=atan(y/x);
if(x<0 && y<0)||(x<0&&y>0)
angle = angle + pi;
end
xr=cos(angle)*r + xc;
yr=sin(angle)*r + yc;
end
0 Kommentare
Antworten (1)
Image Analyst
am 3 Mai 2022
Not sure what you're after, but perhaps this will help. It looks like you're trying to find where the line between two points intersects a circle around the first point.
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
clear; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 20;
markerSize = 40;
% Define parameters
xc=2;
yc=2;
x2=3;
y2=4;
r=1;
% Plot diagram of points and circle.
plot(xc, yc, 'b.', 'MarkerSize', markerSize)
grid on;
hold on;
plot(x2, y2, 'b.', 'MarkerSize', markerSize)
viscircles([xc, yc], r);
axis equal
xlim([0, 4]);
ylim([0, 5]);
% Find the point where the circle intersects
% the line going between the two points.
[xr, yr] = FindSurroundingPoint(xc,yc,x2,y2,r)
% Put line at yr to see where line intersects the circle.
yline(yr, 'Color', 'r', 'LineWidth', 2);
% Put line at xr to see where line intersects the circle.
xline(xr, 'Color', 'r', 'LineWidth', 2);
caption = sprintf('(xr, yr) = (%.3f, %.3f)', xr, yr);
title(caption, 'FontSize',fontSize);
%===================================================================
function [xr, yr] = FindSurroundingPoint(xc,yc,x2,y2,r)
deltax = x2 - xc
deltay = y2 - yc
line([xc, x2], [yc, y2], 'Color', 'b')
angle = atand(deltay/deltax)
if(deltax<0 && deltay<0) || (deltax<0&&deltay>0)
angle = angle + 180
end
xr = cosd(angle) * r + xc
yr = sind(angle) * r + yc
end
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/985935/image.png)
0 Kommentare
Siehe auch
Kategorien
Mehr zu Graphics Object Programming finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!