필터 지우기
필터 지우기

Sweeping a cylinder along a line

조회 수: 5 (최근 30일)
Lorenzo Pollicini
Lorenzo Pollicini 2023년 12월 14일
댓글: Lorenzo Pollicini 2024년 7월 19일
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

채택된 답변

Vinayak
Vinayak 2024년 7월 18일
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:

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Triangulation Representation에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by