Effacer les filtres
Effacer les filtres

Sweeping a cylinder along a line

7 vues (au cours des 30 derniers jours)
Lorenzo Pollicini
Lorenzo Pollicini le 14 Déc 2023
Commenté : Lorenzo Pollicini le 19 Juil 2024 à 7:41
Hello everyone,
I am trying to create an algorithm that automatically builds support structure for Selective Laser Melting produced parts. I am able to extract the points that need supports by a thermal-mechanical analysis which gives me results about the deformations of the part.
Anyway, I am able to define the supported points and define a tree-shaped support structure. Attached is a very simplified version of the script that you can run so to understand the situation I am in.
startPoint = 10*rand(1,3);
normalVector = [0.5, 0.5, -0.5].*rand(1,3);
normalizedVector = normalVector / norm(normalVector);
middlePoint = [startPoint(1), startPoint(2), startPoint(3)] + (startPoint(3)*0.3)* normalizedVector;
plot3([startPoint(1), middlePoint(1)], [startPoint(2), middlePoint(2)], [startPoint(3), middlePoint(3)], 'b');
hold on;
plot3([middlePoint(1), middlePoint(1)], [middlePoint(2), middlePoint(2)], [middlePoint(3), 0], 'r');
Now, I would like to sweep a cylinder of 1 mm diameter along this line, and if possible, connect the two lines with a spline to reduce to avoi the sharp edge. Is there a way to perform what I need?
I have been looking around but couldn't find anything unfortunately.
Thanks in advance for your kind availability and for the time,
LP

Réponse acceptée

Vinayak
Vinayak le 18 Juil 2024 à 5:01
Hi Lorenzo,
To address your query on plotting a cylinder tilted along a reference line defined by two points, here's a function that takes in the start and end points to plot a tilted cylinder:
function plotTiltedCylinder(startPt, endPt, radius, color)
height = norm(endPt - startPt);
[x, y, z] = cylinder([radius, radius], 100);
z = z * height;
dir = endPt - startPt;
dir = dir / norm(dir);
% Create Rotation Matrix
Z = dir / norm(dir);
X = [1, 0, 0];
if abs(dot(Z, X)) > 0.99
X = [0, 1, 0];
end
X = X - dot(X, Z) * Z;
X = X / norm(X);
Y = cross(Z, X);
R = [X; Y; Z]';
cylinderCoords = R * [x(:)'; y(:)'; z(:)'];
x = reshape(cylinderCoords(1, :), size(x)) + startPt(1);
y = reshape(cylinderCoords(2, :), size(y)) + startPt(2);
z = reshape(cylinderCoords(3, :), size(z)) + startPt(3);
surf(x, y, z, 'FaceColor', color, 'EdgeColor', 'none');
end
For further understanding, refer to the following documentation:
To create the spline, you can use the Curve Fitting Toolbox and plot the resulting function. Here's an example using a cubic spline:
splinePoints = [startPoint; middlePoint; [middlePoint(1), middlePoint(2), 0]];
splineCurve = cscvn(splinePoints');
fnplt(splineCurve, 'g', 2);
For more on spline constructions, check out:
This results in something similar to the below image:
  1 commentaire
Lorenzo Pollicini
Lorenzo Pollicini le 19 Juil 2024 à 7:41
Thank you very much!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Triangulation Representation dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by