Cutting a Circular Ring at particular points using angle-theta

조회 수: 10 (최근 30일)
Chris Dan
Chris Dan 2022년 3월 25일
편집: Les Beckham 2022년 3월 25일
Hello,
I am drawing a circular ring using the following code:
clear all; close all;
p = linspace(-1/2,1/2,100);
[X,Y] = meshgrid(p,p); % box mesh
R = p(size(p,2))/2;
r = R/1.5;
alpha = deg2rad(15);
alpha = linspace(-alpha,alpha,50);
[alpha_X,alpha_Y] = meshgrid(alpha,alpha);
theta = atan2(Y,X);
active = (X.^2 + Y.^2 <= R^2 & X.^2 + Y.^2 >= r^2);
figure()
plot(X(active),Y(active),'o','MarkerFaceColor','red');
hold on
This code is incomplete because I have to use alpha and theta to cut the ring at particular points.
The inequalities that I have are:
x^2+y^2<=R^2
x^2+y^2>=r^2
-alpha <=taninv(y/x)<=+alpha.
i have plotted the first two, I am confused as how to plot the third one, alpha one.
Does any on know how to plot the third inequality or how to use it to cut the ring at a particular angle.
the result which i get from above code is:

채택된 답변

Les Beckham
Les Beckham 2022년 3월 25일
편집: Les Beckham 2022년 3월 25일
You were pretty close. See if you can adapt this to get what you want.
p = linspace(-1/2,1/2,100);
[X,Y] = meshgrid(p,p); % box mesh
R = p(size(p,2))/2;
r = R/1.5;
alpha = deg2rad(15);
theta = atan2(Y,X); % check size of theta; note it is already a mesh grid because X and Y are
% the whole circle (radius constraints only)
active = (X.^2 + Y.^2 <= R^2) & (X.^2 + Y.^2 >= r^2);
plot(X(active),Y(active),'o','MarkerFaceColor','red');
% the portion that satisfies the alpha constraint as well
active = (X.^2 + Y.^2 <= R^2) & (X.^2 + Y.^2 >= r^2) & (abs(theta) < alpha);
hold on
plot(X(active),Y(active),'o','MarkerFaceColor','blue');

추가 답변 (1개)

Simon Chan
Simon Chan 2022년 3월 25일
Try to add the follwoing lines:
alphaA = 15*pi/180; % Set the margin, 15 degree here
[thetaA,~] = cart2pol(X,Y);
angleA = abs(thetaA)<=alphaA;
active = (X.^2 + Y.^2 <= R^2 & X.^2 + Y.^2 >= r^2 & angleA);

카테고리

Help CenterFile Exchange에서 Surface and Mesh Plots에 대해 자세히 알아보기

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by