Cutting a Circular Ring at particular points using angle-theta
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Chris Dan
le 25 Mar 2022
Modifié(e) : Les Beckham
le 25 Mar 2022
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:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/941144/image.png)
0 commentaires
Réponse acceptée
Les Beckham
le 25 Mar 2022
Modifié(e) : Les Beckham
le 25 Mar 2022
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');
0 commentaires
Plus de réponses (1)
Simon Chan
le 25 Mar 2022
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);
0 commentaires
Voir également
Catégories
En savoir plus sur Surface and Mesh Plots dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!