Cutting a Circular Ring at particular points using angle-theta

5 次查看(过去 30 天)
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 中查找有关 Scatter Plots 的更多信息

产品


版本

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by