how to plot a section of a circle, need help with coding the math
5 次查看(过去 30 天)
显示 更早的评论
I minored in math but for some reason its always been tough for me to figure out coding math. I have foward looking sonar data and im trying to plot a section of a circle around the sonar. I attached a picture of what im trying to plot. The variables I have is center position (lat and long), I have right and left aperture (130° total), max range (usually 25-30 m), and rotation (heading). How do I plot this section of a circle? Thanks!
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1695856/image.png)
Just to add, Im not sure which r is the radius being plotted, the heading data I have pertains to the middle r in the picture, if thats not the r determining direction of the circle then I could probably subtract direction from the left or right aperture angle? Thanks again.
Second edit:
I figured out how to plot the circle using a different block of code that i found but im having trouble understanding how things are plotted. Below is an image of using the correct radius, theta, orientation and a position of 0,0. What line is being plotted here? I plotted a frame of the sonar at the correct heading and its at a different angle from the triangle plotted below. Thanks again for your help!
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1695871/image.jpeg)
0 个评论
采纳的回答
Adam Danz
2024-5-15
编辑:Adam Danz
2024-5-15
> The variables I have is center position (lat and long), I have right and left aperture (130° total), max range (usually 25-30 m), and rotation (heading). How do I plot this section of a circle?
I assume this is plotted in Cartesian coordinates and that the center point is defined by [latitude, longitude] which, in Cartesian coordinates, is [y,x].
center = [42.30027404055592, -71.35168003446316];
rightAp = 15; % deg
leftAp = 15; % deg
radius = 25; % max range
heading = 45; % deg
th = linspace(heading-leftAp, heading+rightAp, 100);
x = [center(2), sind(th) * radius + center(2), center(2)];
y = [center(1), cosd(th) * radius + center(1), center(1)];
plot(x,y, '-k');
axis equal
% Add reference line
hold on
plot([center(2), sind(heading)*radius+center(2)], ...
[center(1), sind(heading)*radius+center(1)], '--k')
更多回答(1 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!