Sum inside a "bouncing" domain
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
I have a set of positions given by x and y.
Considering a point yf, I want to know what's the value of yi, when the difference along y, is given by dy.
The difference dy is applied considering this difference to bounce within its domain.
To explain myself better, below an example where the outcome has been "hardcoded".
Starting from the final black point, I'd like to find the initial red point where the difference between these two is computed in terms of absolute value along its path.
% Vertical difference:
dy = 3/4*pi;
% Options:
a = pi/3;
N = 361;
f = @(x) asin(sin(a)*sin(x));
% Data:
x = linspace(0,2*pi,N);
y = f(x);
% Final point:
xf = 5/3*pi;
yf = f(xf);
% Find initial point:
% - a+yf = deltaY between black point and -a
% - 2*a = deltaY between -a and a
% - dy-(a+yf+2*a) = deltaY to be removed from a to obtain final point
yi = a-(dy-(a+yf+2*a));
g = @(x) f(x) - yi;
xi = fzero(g,0);
% Figure:
figure;
hold on;
plot(x,y);
scatter(xf,yf,50,'k','filled');
scatter(xi,yi,50,'r','filled');
hold off;
grid on;
In other terms, the condition to be satisfied is:
tol = 1e-4;
xCheck = linspace(xi,xf,1/tol);
dy - sum(abs(diff(f(xCheck)))) < tol
Because I'm intereseted only in the value of y, my approach is do to the following:
% My approach:
direction = -sign(gradient(y)+eps);
YI = direction.*(mod(a + y + direction*dy, 2*a) - a);
% Figure:
figure;
hold on;
plot(y);
plot(YI);
hold off;
grid on;
I can see I'm almost there except for the middle part which is flipped.
The proper outcome should be:
% Find indeces of wrong values and flip them:
swapIdx = find(diff(YI(1,:)) > a);
wrongIdx = swapIdx(1)+1:swapIdx(2);
YI(wrongIdx) = -YI(wrongIdx);
% Figure:
figure;
hold on;
plot(y);
plot(YI);
hold off;
grid on;
The variable swapIdx identifies two intervals, one of which is correct, while the other has to be flipped.
At the moment I hardcoded a way to find what interval is wrong and flip it, but I'm almost sure there should be an easier way to sovle the problem.
My limitation is that I don't know the real name of what I'm calling "bouncing domains" and I fail to gather proper knowledge.
Thanks in advance.
0 comentarios
Respuestas (1)
Steven Lord
el 23 de En. de 2024
Since you have point coordinates you have an approximation to your continuous curve as a series of line segments. See the "General approach" section of that Wikipedia page. When you find the line segment on which your desired point is located (where the arc length to one endpoint is smaller than your desired distance and the arc length to the other endpoint is greater) determine where along that line segment the point needs to be located.
1 comentario
chicken vector
el 25 de En. de 2024
Editada: chicken vector
el 25 de En. de 2024
Ver también
Categorías
Más información sobre Two y-axis en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!