Handling Numerical Instability in Estimating Angle Between 2D Points
Hi! I would like to estimate the angle between points using the following code.
x = randn(10000, 1); y = randn(10000, 1);
angle_mat = zeros(length(x));
for i = 1:length(x)
for j = 1:length(x)
if i ~= j
angle_mat(i,j) = atan2(y(j)-y(i), x(j)-x(i));
else
angle_mat(i,j) = NaN;
end
end
end
I realized, however, that, due to numerical instability near horizontal/vertical slopes, the angle estimate near 0/+-pi became weird. Does anyone know how to acount for this numerical instability?Hi! I would like to estimate the angle between points using the following code.
x = randn(10000, 1); y = randn(10000, 1);
angle_mat = zeros(length(x));
for i = 1:length(x)
for j = 1:length(x)
if i ~= j
angle_mat(i,j) = atan2(y(j)-y(i), x(j)-x(i));
else
angle_mat(i,j) = NaN;
end
end
end
I realized, however, that, due to numerical instability near horizontal/vertical slopes, the angle estimate near 0/+-pi became weird. Does anyone know how to acount for this numerical instability? Hi! I would like to estimate the angle between points using the following code.
x = randn(10000, 1); y = randn(10000, 1);
angle_mat = zeros(length(x));
for i = 1:length(x)
for j = 1:length(x)
if i ~= j
angle_mat(i,j) = atan2(y(j)-y(i), x(j)-x(i));
else
angle_mat(i,j) = NaN;
end
end
end
I realized, however, that, due to numerical instability near horizontal/vertical slopes, the angle estimate near 0/+-pi became weird. Does anyone know how to acount for this numerical instability? matlab, numerical instability MATLAB Answers — New Questions