Finding values within a 3D Array
Ältere Kommentare anzeigen
The problem I have is that I have a 3D array with the dimension of 181x361x1931. If I was to simulate a line at any point through the 3D array, is there a way to retrieve all the data that the simulated line would penetrate through and store them within a new array.
I have seen various answers that deals with a 2D array, but haven't seen anybody answer a question regarding a 3D array. I have also seen that there are various packages on Matlab that deals with Bresenham Line Algorithm in 3D matrix, but like I said the line is imaginary thus, i don;t have much of an idea of how to go about it. I was purely wondering if there is an easier way of doing such calculations.
5 Kommentare
Mathieu NOE
am 16 Apr. 2024
if your line goes through existing points of your 3D array, I don't see why this would be difficult;
if your line has an arbitrary trajectory, it may simply not go through any point; what are we supposed to do in that case ? interpolation ?
Rik
am 17 Apr. 2024
Perhaps you need my point_to_line_distance function? Or findND? At any rate, your question is not clear enough to give an actual suggestion.
Chunru
am 17 Apr. 2024
If the 3D data array and line coordinates are known, the interp3 function can be used to retrieve the data.
Tianchu Lu
am 24 Apr. 2024
Hi Tianchu ,
I understand you're looking for a method to simulate a line through a 3D array of dimensions 181x361x1931 in MATLAB and retrieve all data points that this line intersects. To retrieve data points from a 3D array that a simulated line would penetrate through, you can indeed use various approaches, including geometric algorithms and interpolation methods. The “interp3” function in MATLAB can be used for this purpose. Interpolation is a method of estimating values between two known values. “interp3” specifically works with 3D data, making it suitable for your needs.
This approach involves defining the line by its start and end points in the 3D space and then interpolating the values at regular intervals along this line. Below is one sample example to help you understand 3d interpolation in a better way:
% Assuming 'data' is your 3D array
data = rand(181, 361, 1931);
% Define the line's start and end points
startPoint = [1, 1, 1]; % Adjust as necessary
endPoint = [181, 361, 1931]; % Adjust as necessary
% Generate points along the line
numPoints = 1000; % Number of points, adjust based on desired resolution
x = linspace(startPoint(1), endPoint(1), numPoints);
y = linspace(startPoint(2), endPoint(2), numPoints);
z = linspace(startPoint(3), endPoint(3), numPoints);
% Retrieve the values along the line
lineValues = interp3(data, x, y, z, 'linear'); % 'linear' interpolation
The example uses linear interpolation, but MATLAB offers other methods ('nearest', 'cubic', 'spline') depending on your data's nature and your accuracy needs. For more detailed guidance or alternative approaches, you can explore below MATLAB's documentation.
Hope this helps!
Akzeptierte Antwort
Weitere Antworten (0)
Kategorien
Mehr zu Multidimensional Arrays finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!