How can I convert a 2d plot of a circular object into a binary array where points inside the curve = 1 ?
이전 댓글 표시
I have a function that gives me the x and y coordinates of a circle with saw shaped teeth on its interior. I'm looking to convert this into a binary array where the area within the border of this function is 1 and the area outside is 0. Ideally, this can be done in a way where the resolution of the grid can be changed (eg. a 20 cm circle with 50 1cm teeth in a 50x50cm grid sampled at .01cm).
I've tried using getframe(gcf) on the plot(x,y) to extract the plot into a matrix but this seems inelegant and it doesn't allow for easy contol over grid resolution.
function[x,y] = serratedap(radius,numteeth,toothheight,N)
% N = 10000 Theta resolution
% all units are in mm
% h=27.344 tooth height
% radius = 104.7635 radius of the circle without teeth
% numteeth =213 number of teeth
theta = linspace(0,2*pi,N) ;
p = 2*pi/numteeth;
rho = radius*(1 + toothheight*(p/2-p*abs(round(theta/p)-theta/p)));
x = rho.*cos(theta);
y = rho.*sin(theta);
I'm somewhat new to MATLAB so any other approaches to this problem or general advice would be greatly appreciated.
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Matrices and Arrays에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!