create grid in polar coordinates
43 ビュー (過去 30 日間)
古いコメントを表示
I have obtained an image in cartesian coordinates that looks like this, with a semi-circular shape. I would like to deduce the polar coordinates of each point in which the reference points are the following:
- for the radius, the zero is at the center left of the image (and the maximal value would be 150 at the top left or center right)
- for the angle, the zero would be at the bottom left of the image
So if I start to create two grid matrices for (rho,theta) coordinates that would map my initial matrix, it would look like this (of course I would want the same number of elements between the three matrices, here is just a simplified version with smaller size) :
I don't want how to fill the interrogation marks... Which functions should I use? I tried meshgrid but it could not make it work...
Thank you for your help!
rho_matrice=[150 ? ? ? ?;
100 ? ? ? ?;
50 ? ? ? ?;
0 50 10 150;
50 ? ? ? ?;
100 ? ? ? ?
150 ? ? ? ?];
theta_matrice=[pi ? ? ?;
5pi/6 ? ? ?
2pi/3 ? ? ?;
pi ? ? ?
2pi/6 ? ? ?
1pi/6n ? ? ?
0 pi/6 2*pi/6 pi]
回答 (1 件)
Voss
2023 年 1 月 8 日
After constructing your x- and y-coordinates with meshgrid, you can use cart2pol to convert them to polar coordinates.
x = 0:50:150;
y = 150:-50:-150;
[x_matrice,y_matrice] = meshgrid(x,y)
[theta_matrice,rho_matrice] = cart2pol(x_matrice,y_matrice)
Note cart2pol uses the standard convention that theta is zero in the center-right of the image (corresponding to x = 150, y = 0, the positive x-axis). Since you want theta to be zero in the bottom left of the image (corresponding to x = 0, y = -150, the negative y-axis), you can add pi/2 to theta_matrice to make it conform to your convention.
theta_matrice = theta_matrice+pi/2
2 件のコメント
Voss
2023 年 1 月 9 日
You're welcome! Any questions, let me know. Otherwise, please "Accept This Answer". Thanks!
参考
カテゴリ
Help Center および File Exchange で Surface and Mesh Plots についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!