Check if a 2D Point lies on a given Arc or not

7 views (last 30 days)
Hi,
I have set of 2D Points ,which represent an Arc.
I would like to know if a certain 2D Point lies on this arc or not (with some tolerance).
My 2D Points representing the arc are as follows:
0 0
0.00510736 0.0485933
0.00851245 0.0809906
0.0119173 0.113385
0.0153224 0.145782
0.0187272 0.178177
0.0400463 0.225069
0.0775509 0.270257
0.0971418 0.300953
0.132944 0.329943
0.168746 0.358935
0.204548 0.387925
0.238648 0.400718
0.27445 0.429708
0.30855 0.442501
0.34265 0.455295
0.376749 0.468089
0.410849 0.4
80879
0.444949 0.493673
0.477346 0.490268
0.509718 0.486866
0.542115 0.48346
0.574512 0.480055
0.639307 0.473245
0.671704 0.46984
0.71861 0.448532
0.751007 0.445127
0.783405 0.441722
0.814087 0.422123
0.843079 0.38632
0.888267 0.348818
0.901061 0.314718
0.913855 0.280621
0.926646 0.246522
0.939439 0.212424
0.952233 0.178325
0.965027 0.144225
0.977818 0.110128
0.974413 0.0777306
0.987206 0.0436334
1 0.00953356
Now,I would like to check,if a certian 2D Point i.e. (0.965027 0.144225) lies on the given arc or not.
end
Thanks in advance!

Answers (1)

Adam Danz
Adam Danz on 16 Nov 2018
Edited: Adam Danz on 26 Feb 2019
My solution calculates the euclidean distance between the 'test point' to all points on the arc. If the minimum distance is below threshold, a message prints to the screen confirming that the test point is "on" the arc. If not, a message displays saying that the point is not on the arc. The threshold is set in the code; it's a maximum euclidean distance allowed from the arc.
To test, try point [0.1 0.3] which is at a distance of 0.003 from the 9th point on the arc. Whether that's on or off the arc depends on how you set your tolerance. In my code it's set to 0.001 so this example would be considered "off" the arc. See text below for limitations.
% Your data (cleaned up)
p = [0 0
0.00510736 0.0485933
0.00851245 0.0809906
0.0119173 0.113385
0.0153224 0.145782
0.0187272 0.178177
0.0400463 0.225069
0.0775509 0.270257
0.0971418 0.300953
0.132944 0.329943
0.168746 0.358935
0.204548 0.387925
0.238648 0.400718
0.27445 0.429708
0.30855 0.442501
0.34265 0.455295
0.376749 0.468089
0.410849 0.480879
0.444949 0.493673
0.477346 0.490268
0.509718 0.486866
0.542115 0.48346
0.574512 0.480055
0.639307 0.473245
0.671704 0.46984
0.71861 0.448532
0.751007 0.445127
0.783405 0.441722
0.814087 0.422123
0.843079 0.38632
0.888267 0.348818
0.901061 0.314718
0.913855 0.280621
0.926646 0.246522
0.939439 0.212424
0.952233 0.178325
0.965027 0.144225
0.977818 0.110128
0.974413 0.0777306
0.987206 0.04363341
];
% Here's the test point
testpoint = [0.965027 0.144225];
% Visualize the arc and test point
plot(p(:,1), p(:,2), 'o-')
hold on
plot(testpoint(1), testpoint(2), 'r*', 'linewidth', 2)
% Calculate distance of testpoint to all other points
d = sqrt((testpoint(1) - p(:,1)).^2 + (testpoint(2) - p(:,2)).^2);
% Find minimum distance
[minDist, minDistIdx] = min(d);
% Set tolerance and determine if testpoint is concidered 'on' arc
tol = 0.001; % this is the max distance allowed to be considered 'on' arc.
if minDist < tol
% The testpoint is considered to be "on" the arc
fprintf('Testpoint is on the arc at index number %d with a distance of %.5f\n', minDistIdx, minDist);
else
fprintf('Testpoint is NOT on the arc but is closest to index number %d with a distance of %.5f\n', minDistIdx, minDist);
end
Testpoint is on the arc at index number 37 with a distance of 0.00000
A considerable limitation to this method is when the test point is "on" the arc but between two points. Consider the point [0.153, 0.3448]. That point is on the interpolated arc but not near any of the points. If you'd like to consider these cases you'll need to interpolate the points on your arc prior to calculating the distance.
  11 Comments
sri harsha chilakamarri
sri harsha chilakamarri on 20 Nov 2018
Edited: sri harsha chilakamarri on 20 Nov 2018
@Adam: yeah,I get your logic, but somehow not able to put this logic into the code :(.Could you please elaborate more on "carefully looking at the angle results"
Adam Danz
Adam Danz on 20 Nov 2018
Edited: Adam Danz on 20 Nov 2018
Previously I suggested calculating the angle from vertical but your reference line is arbitrary and the math is easier if the reference line is horizontal so in this example we'll use a horizontal reference angle.
Let's say that the center of your fitted circle is at (x,y) and you're calculating the angle between horizontal and point (a,b) passing through the center of the circle.
1) You need the slope of each line. The horizontal slope is 0 (no math needed). The slope of the line passing through (x,y) and (a,b) is just
m = (b-y)/(a-x);
2) The angle between two lines is calculated by
angle = atan((mb - ma) / (1 + (ma * mb)));
where mb and ma are the slopes of the two lines and angle is in radians. So just plug in your two slopes to get the inner angle. If you want the result in degrees,
angDeg = (180/pi) * angRadians;
You'll need to do that for all of your points and avoid using a loop; all the math above can be vectors that cover all of your points.
3) Now you've got a bunch of angles, one for each of your points. Look at the data. Are they as expected? If your points pass through the x axis, are any of the angles calculated in the 'wrong' direction? Are the signs as expected? Try a bunch of variations to make sure you don't need to adjust the direction of the angle for dots that pass the x axis.
4) After you confirm that your data are correct, all you need to do is calculate the difference between the max and min angle to get the inner angle of your arc.
5) Now you can calculate arc length via the equation below (note use of degrees)
arcLength = (innerAngle / 360) * circumference;

Sign in to comment.

Categories

Find more on Mathematics in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!