How to speed up the process of determining if a point is inside a cylinder
Afficher commentaires plus anciens
I would like to speed up the process of determining if a point is inside a cylinder. Specifically:
A 3D cubic mesh is used to divide a problem. In 3 separate 3D arrays the cell center coordinates are stored (i.e cx, cy, cz). A cylinder is upright either in the x, y, or z direction. Then based on the cap center coordinates, the height of the cylinder, and the radius of the cylinder, the following code is used to determine if a point is inside the cylinder:
% nx, ny, nz is the number of cells in cx, cy or cz.
% range = distance between the cap centers of the cylinder
% For all points in the mesh
for lind = 1:nx
for jnd = 1:ny
for knd = 1:nz
% Get cell center coordinates (x, y, z)
apoint = [cx(lind,jnd,knd) cy(lind,jnd,knd) cz(lind,jnd,knd)];
% Project point on center line
tmin(lind, jnd, knd) = (dot(apoint, range) - dot(cap1, range))/ ...
dot(range, range);
linept = cap1 + (tmin(lind, jnd, knd) * range);
% Distance form center line
diff = linept - apoint;
dist(lind, jnd, knd) = sqrt(dot(diff, diff));
end
end
end
% Get all the indices of the points that are part of the cylinder
l = find((((tmin>=0) & (tmin<=1)) & (dist<=radius)));
How can I speed up the computation of determining whether a point is part of a cylinder specifically avoid using for-loops?
Any help would be much appreciated!
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Startup and Shutdown dans Centre d'aide et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!