I would like to return the current point from a polar plot in polar coordinates.
MATLAB: Can I return the ‘CurrentPoint’ property of the current axis of a polar plot in polar coordinates
MATLAB
Related Solutions
use cart2pol function
Written in r2020a update 3
Symptoms of the problem
The current mouse position within an axes (ax.CurrentPoint) has a limit of precision such that the true (0,0) coordinate (and other specific coordinates) cannot be manually selected from the CurrentPoint property along the x axis.
Demonstrating the problem
The code below creates a square axes with axis limits from -1:1 and dashed crosshairs at x=0 and y=0 for reference. The figure contains a WindowButtonMotionFcn that updates text in the upper, left corner of the axes indicating the current mouse position within the axes. A second line of text ("delta") shows the distance between the previous and current mouse position. It also contains blue crosshairs that follow the current mouse position.
With a sensitive mouse and some patience, align the blue crosshairs with the reference lines at (0,0) and you'll notice that the current y-coordinates matches y=0 but the current x-coordinate cannot match x=0.
figure()ax = axes('FontSize', 20, 'XTick', -1:.2:1, 'YTick',-1:.2:1);axis equalxlim([-1 1])ylim([-1 1])xline(0, 'k--')yline(0, 'k--')grid onth = text(min(xlim), max(xlim), '', 'FontSize', 16, 'VerticalAlignment', 'top');crosshairs(1) = xline(max(xlim),'b--');crosshairs(2) = yline(max(ylim),'b--');set (gcf, 'WindowButtonMotionFcn', {@mouseMove, th, ax, crosshairs});hold ondrawnowfunction mouseMove(~, ~, th, ax, crosshairs)persistent cursorPosif ~isempty(cursorPos) delta = abs(cursorPos - ax.CurrentPoint(1,1:2));else delta = [nan, nan]; endcursorPos = ax.CurrentPoint(1,1:2);th.String = sprintf('(%.5f, %.5f)\n(%.5f, %.5f) delta', ax.CurrentPoint(1,1:2), delta);crosshairs(1).Value = ax.CurrentPoint(1,1);crosshairs(2).Value = ax.CurrentPoint(1,2);end
In the example below, the cursor is as close as possible to (0,0) and the error between the perceived coordinate and the actual selected coordinate is at 0.00122.
Magnitude and direction of the error
The magnitude and direction of the error between the perceived selected coordinate and the actual selected coordinate depends on
- Axis size
- Figure size (when axes resize with the figure)
- Axis limits
- Axis aspect ratio
- Monitor resolution
- Location of the selected coordinate within the same axes.
Change any of those properties and the magnitude and direction of the error will likely change. Since the error changes with different coordinates within the exact same axes, the magnitude and direction of error cannot be corrected. However, zooming into an area of interest and reducing the range of axis limits will decrease the magnitude of the error.
The cause of the problem
The precision of coordinate selection is limited by the arrangement of pixels on your monitor. When you select a point, you are selecting a pixel. That pixel will often have a relatively small offet from the actual coordinate you intended to select. Zooming into the axes is equivalent to decreasing the pixel size relative to the axes which increases precision. The problem is analgous to roundoff error.
Going back to the demo figure above, the mouse is as close as possible to (0,0) but the current coordinate reads (0.0012, 0.0000). If we add a marker at that location and another marker at (0,0), the two coordinates are indistinguishable while holding the axis and figure properties constant.
plot(0.0012, 0.0000, 'rx','MarkerSize', 20)plot(0.0000, 0.0000, 'bx','MarkerSize', 12)
You can see that blue x is directly on the red x even though they have slighly different coordinates. Then, zoom into that point and you will see that they separate. This demonstrates the limit or precision at different axis scales.
Zoom into the axes, the difference between the two coordinates becomes visible.
xlim([-.01, .01])ylim([-.01, .01])
Solution to the problem
In short, there is no simple solution. I suppose MathWorks could recalibrate the bias such that (0,0) can always be selected, but that would only fix the error at that coordinate.
Since the error is different for different coordinates within the same identical axes, you cannot simply measure a constant bias and offset all selected coordinates by that bias.
The only way to increase precision is by zoom into the region of interest and selected the coordinate within a narrow range of axis limits.
If selecting specific targets such as (0,0) is important, you could compute the distance between the CurrentPoint and all targets and select the target closest to the point.
Lastly, buying a monitor with higher resolution will also decrease, but not eliminate, the error.
Best Answer