Sweeping a cylinder along a line
7 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
采纳的回答
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 Center 和 File Exchange 中查找有关 Data Analysis 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!