Line Integral under surface

7 ビュー (過去 30 日間)
HAMID
HAMID 2021 年 11 月 16 日
回答済み: Brahmadev 2024 年 4 月 10 日 9:46
Here is what I am trying to do (I am relatively new to MatLab):
  • I have a surface defined from an excel sheet (data.csv). This is a screenshot of the surface:
  • Surface was generated from the following code (excel sheet is attached):
clear; clc;
% Read table:
T = readtable('data.csv');
% Plot surface:
x = T.(1)*180 ;
y = T.(2)*180 ;
z = T.(3) ;
xi = linspace(min(x),max(x));
yi = linspace(min(y),max(y));
[X,Y] = meshgrid(xi,yi);
Z = griddata(x,y,z,X,Y);
surf(X,Y,Z)
shading interp
colorbar
  • I have a straight segmant connecting two random points {P1, P2} on the XY plane (see figure above as an example).
  • How can I calculate the area between this segment and the surface?

回答 (1 件)

Brahmadev
Brahmadev 2024 年 4 月 10 日 9:46
Hi @HAMID,
You can find the area along any line for the surface given by using the "interp2" to interpolate th function along the specific points and then applying the basic definition for the area of a trapezium. The area of a trapezium is A = (a+b)*h/2 where a and b are the heights of the parallel sides and h is the distance between them. Please see example below:
clear; clc;
% Read table:
T = readtable('data.csv');
% Plot surface:
x = T.(1)*180 ;
y = T.(2)*180 ;
z = T.(3) ;
xi = linspace(min(x),max(x));
yi = linspace(min(y),max(y));
[X,Y] = meshgrid(xi,yi);
Z = griddata(x,y,z,X,Y);
surf(X,Y,Z)
shading interp
colorbar
% Assuming points P1 and P2 and interpolating Z values on the surface along
% the connecting line
x1 = xi(1); x2 = xi(100);
y1 = yi(1); y2 = yi(100);
t = linspace(0, 1, 100); % 100 points along the line
x_line = x1 + t * (x2 - x1);
y_line = y1 + t * (y2 - y1);
z_line = interp2(X, Y, Z, x_line, y_line);
hold on
plot3(x_line,y_line, z_line);
dx = sqrt((x_line(2)-x_line(1))^2+(y_line(2)-y_line(1))^2);
Area = 0;
for i = 1:length(z_line)-1
% Itreratively find area of trapezium
Area = Area + (z_line(i)+z_line(i+1)/2)*dx;
end
Hope this helps!

カテゴリ

Help Center および File ExchangeSurface and Mesh Plots についてさらに検索

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by