필터 지우기
필터 지우기

How to map a point inside a circle to circle area in MATLAB?

조회 수: 2 (최근 30일)
H D
H D 2017년 1월 30일
답변: Image Analyst 2022년 5월 3일
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

답변 (1개)

Image Analyst
Image Analyst 2022년 5월 3일
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

카테고리

Help CenterFile Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by