Line integral over a 3D surface
Mostrar comentarios más antiguos
I have a surface defined by its x,y,z coordinates and want to find, fixed two points (x1,y1) and (x2,y2) the line integral over the surface of this two points. How can I do it?
2 comentarios
darova
el 22 de En. de 2020
What have you tried? Did you try interp2?
Riccardo Giaffreda
el 22 de En. de 2020
Respuestas (2)
darova
el 22 de En. de 2020
Here is a short example
[X,Y,Z] = peaks(20);
x = linspace(-2,2,50);
y = linspace(-1,3,50);
z = interp2(X,Y,Z,x,y);
surf(X,Y,Z)
alpha(0.2)
hold on
plot3(x,y,z,'.-r')
hold off
I don't understand what do you mean by linear integral? What do you want to calculate?
2 comentarios
Riccardo Giaffreda
el 22 de En. de 2020
darova
el 22 de En. de 2020
You mean length of the curve?
Riccardo Giaffreda
el 22 de En. de 2020
0 votos
4 comentarios
Nick Gibson
el 15 de Ag. de 2022
I could use this too!
Think darova's answer above is getting close.
If, instead of using 50 sample points for z, you worked out how many points you needed to replicatate the same sample (pixel) spacing as in the original x and y directions (form the angle of the line) and used that number instead, you'd be about there. Then just sum the values in z from these. Would that do it?
If you mean integrating over the straight line connecting x1 and x2, you can do
f = @(x,y) x.^2+y.^2;
x1 = [-19,1];
x2 = [-9,-9];
line_integral = norm(x2-x1)*integral(@(t)f(x1(1)+t*(x2(1)-x1(1)),x1(2)+t*(x2(2)-x1(2))),0,1)
Nick Gibson
el 16 de Ag. de 2022
thanks, yeah, exactly, just integrate over a straight line.
though you've lost me in the last line of code there!
and the first line is I assume to generate an example function?
Think that would work if the data you want to integrate over is a nice function, but mine is just a sample 2-D grid of data, so not sure your suggestion will work for that - can it be adapted?
You will have to be able to evaluate your function over the line connecting x1 and x2 - be it that you have scattered data or an explicit function definition as above. So the code applies in any case - you will have to supply the f-values somehow.
A parametrization of the line connecting x1 and x2 is given by
p(t) = x1 + s*(x2-x1) for s in [0 1].
norm(p'(t)) = norm(x2-x1)
The above formula follows if you read Line integral of a scalar field under
Categorías
Más información sobre Surface and Mesh Plots en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
