Line integral over a 3D surface

13 Ansichten (letzte 30 Tage)
Riccardo Giaffreda
Riccardo Giaffreda am 22 Jan. 2020
Bearbeitet: Torsten am 16 Aug. 2022
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 Kommentare
darova
darova am 22 Jan. 2020
What have you tried? Did you try interp2?
Riccardo Giaffreda
Riccardo Giaffreda am 22 Jan. 2020
This is what I tried:
The first part of the code is what gives me the 3D plot and value of the function. The important part is the matrix SF_Full which gives tha value on the surface of the function. I am asking about the second part
clear all
clc
Sampling_Map = 1;
SF_Mean = 0;
SF_Sigma = 6;
R = 50;
x = [ -R : Sampling_Map : R];
y = [ -R : Sampling_Map : R];
Num_Sample_Map = length(x);
SF_Sample = [ 1: 15 : Num_Sample_Map];
Num_Sample_SF = length(SF_Sample);
[X,Y] = meshgrid(x,y);
SF = zeros(Num_Sample_Map,Num_Sample_Map);
SF(SF_Sample,SF_Sample)= 6*(randn(Num_Sample_SF,Num_Sample_SF));
figure (1)
SF_Full=griddata(x(SF_Sample)',y(SF_Sample)',SF(SF_Sample,SF_Sample),X,Y,'cubic');
mesh(x,y,SF_Full)
hold on
plot3(X(SF_Sample,(SF_Sample)),Y(SF_Sample,(SF_Sample)),SF(SF_Sample,SF_Sample),'o')
hold off
Given two points on the map, for example x1=(-19,1) and x2(-9;-9) this is what I did to get the integral. Do you think it can work for any couple of numbers?
hold on
t = [-19:1:-9];
v = [1:-1:-9];
plot(t,v)
SUM=zeros(1,length(v));
for i=1:length(v)
SUM(i)= SF_Full(v(i)+R+1, t(i)+R+1); % +R+1 is for mapping the value on the plot and the corresponding on the matrix
end
Q= trapz( SUM )

Melden Sie sich an, um zu kommentieren.

Antworten (2)

darova
darova am 22 Jan. 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 Kommentare
Riccardo Giaffreda
Riccardo Giaffreda am 22 Jan. 2020
The integral over the segment (the one in red in your plot, the one with x1 and x2 as ends in mine)
darova
darova am 22 Jan. 2020
You mean length of the curve?

Melden Sie sich an, um zu kommentieren.


Riccardo Giaffreda
Riccardo Giaffreda am 22 Jan. 2020
No, the line integral from x1=(-19,1) to x2(-9;-9) of the function SF_Full.
Cattura.PNG
  4 Kommentare
Nick Gibson
Nick Gibson am 16 Aug. 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?
Torsten
Torsten am 16 Aug. 2022
Bearbeitet: Torsten am 16 Aug. 2022
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

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Discrete Data Plots finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by