DIY 3D Scanner with Mtalab data convert
15 次查看(过去 30 天)
显示 更早的评论
Hello people,
I have big troubles with my DIY 3D-Scanner. But first I have to give you some Backround:
I scan an object with the time-of-flight principes. An I want so analyse my raw measurement data with some Matlab code. And in the end I have
three matrices with my x,y, and z points. But now I just have a thin surface . Specialy just the surface I scanned. Now I have to create a bottom and a lid.
My Idea was so fill the parts of my plot with fill3(); an in my plot I get the correct form. But I cants transform it with surf2stl();
To summerrize my Question: Has anybody an idea to put on a bottom an lid at the sidewall? So I can transorm a closed body with surf2stl();?
Thanks for your Answers!
Of course her is my code:
load census; steps=200;
alpha=[0,18,36,54,72,90,108,126,144,162,180,198,216,234,252,270,288,306,324,342,360,378,396,414,432,450,468,486,504,522,540,558,576,594,612,630,648,666,684,702,720,738,756,774,792,810,828,846,864,882,900,918,936,954,972,990,1008,1026,1044,1062,1080,1098,1116,1134,1152,1170,1188,1206,1224,1242,1260,1278,1296,1314,1332,1350,1368,1386,1404,1422,1440,1458,1476,1494,1512,1530,1548,1566,1584,1602,1620,1638,1656,1674,1692,1710,1728,1746,1764,1782,1800,1818,1836,1854,1872,1890,1908,1926,1944,1962,1980,1998,2016,2034,2052,2070,2088,2106,2124,2142,2160,2178,2196,2214,2232,2250,2268,2286,2304,2322,2340,2358,2376,2394,2412,2430,2448,2466,2484,2502,2520,2538,2556,2574,2592,2610,2628,2646,2664,2682,2700,2718,2736,2754,2772,2790,2808,2826,2844,2862,2880,2898,2916,2934,2952,2970,2988,3006,3024,3042,3060,3078,3096,3114,3132,3150,3168,3186,3204,3222,3240,3258,3276,3294,3312,3330,3348,3366,3384,3402,3420,3438,3456,3474,3492,3510,3528,3546,3564,3582,0,18,36,54,72,90,108,126,144,162,180,198,216,234,252,270,288,306,324,342,360,378,396,414,432,450,468,486,504,522,540,558,576,594,612,630,648,666,684,702,720,738,756,774,792,810,828,846,864,882,900,918,936,954,972,990,1008,1026,1044,1062,1080,1098,1116,1134,1152,1170,1188,1206,1224,1242,1260,1278,1296,1314,1332,1350,1368,1386,1404,1422,1440,1458,1476,1494,1512,1530,1548,1566,1584,1602,1620,1638,1656,1674,1692,1710,1728,1746,1764,1782,1800,1818,1836,1854,1872,1890,1908,1926,1944,1962,1980,1998,2016,2034,2052,2070,2088,2106,2124,2142,2160,2178,2196,2214,2232,2250,2268,2286,2304,2322,2340,2358,2376,2394,2412,2430,2448,2466,2484,2502,2520,2538,2556,2574,2592,2610,2628,2646,2664,2682,2700,2718,2736,2754,2772,2790,2808,2826,2844,2862,2880,2898,2916,2934,2952,2970,2988,3006,3024,3042,3060,3078,3096,3114,3132,3150,3168,3186,3204,3222,3240,3258,3276,3294,3312,3330,3348,3366,3384,3402,3420,3438,3456,3474,3492,3510,3528,3546,3564,3582,0,18,36,54,72,90,108,126,144,162,180,198,216,234,252,270,288,306,324,342,360,378,396,414,432,450,468,486,504,522,540,558,576,594,612,630,648,666,684,702,720,738,756,774,792,810,828,846,864,882,900,918,936,954,972,990,1008,1026,1044,1062,1080,1098,1116,1134,1152,1170,1188,1206,1224,1242,1260,1278,1296,1314,1332,1350,1368,1386,1404,1422,1440,1458,1476,1494,1512,1530,1548,1566,1584,1602,1620,1638,1656,1674,1692,1710,1728,1746,1764,1782,1800,1818,1836,1854,1872,1890,1908,1926,1944,1962,1980,1998,2016,2034,2052,2070,2088,2106,2124,2142,2160,2178,2196,2214,2232,2250,2268,2286,2304,2322,2340,2358,2376,2394,2412,2430,2448,2466,2484,2502,2520,2538,2556,2574,2592,2610,2628,2646,2664,2682,2700,2718,2736,2754,2772,2790,2808,2826,2844,2862,2880,2898,2916,2934,2952,2970,2988,3006,3024,3042,3060,3078,3096,3114,3132,3150,3168,3186,3204,3222,3240,3258,3276,3294,3312,3330,3348,3366,3384,3402,3420,3438,3456,3474,3492,3510,3528,3546,3564,3582]' * (pi/1800);
radius=[276,274,278,276,270,268,276,278,272,282,282,280,290,278,276,272,284,280,282,268,280,270,282,274,286,286,270,284,282,284,286,274,276,288,282,286,280,282,288,278,288,286,290,294,296,280,286,294,288,288,288,286,286,290,292,292,306,290,300,302,284,302,292,292,292,294,304,286,286,290,298,310,294,304,306,292,296,300,296,298,300,300,304,312,308,304,308,310,296,300,294,298,294,312,298,294,300,312,306,300,304,306,302,304,308,302,312,300,300,308,304,300,306,292,290,300,302,290,288,298,300,296,298,298,308,312,298,298,296,298,292,298,300,298,284,300,294,288,290,294,284,288,302,292,296,302,298,282,290,288,278,288,280,286,294,284,300,284,298,282,274,280,298,280,278,280,282,272,280,282,278,274,278,280,266,282,284,274,276,274,276,276,288,274,270,274,278,280,274,270,274,280,276,272,276,282,278,284,284,284,284,270,274,266,274,286,282,276,270,286,286,276,282,278,270,270,278,280,276,274,270,276,282,270,280,292,288,276,274,282,280,280,282,286,290,276,286,282,292,284,300,286,290,290,294,286,288,290,290,294,298,290,296,284,282,288,286,294,294,292,294,296,296,300,298,292,296,302,302,296,296,298,300,292,306,296,300,292,286,300,294,298,294,298,312,304,300,294,302,298,298,296,290,300,298,296,302,298,294,300,304,298,308,292,302,300,296,298,300,302,300,294,292,302,298,298,300,294,292,302,296,296,290,302,304,298,304,300,296,298,296,288,298,288,296,298,300,288,296,286,290,288,292,292,298,288,294,286,280,292,288,290,284,282,282,286,286,290,288,288,286,294,290,282,280,280,282,286,278,276,270,272,280,276,276,278,280,274,278,276,276,278,278,286,278,274,280,278,274,272,276,276,266,272,276,272,274,270,274,282,268,264,256,262,264,258,266,258,256,262,256,258,248,270,272,260,264,268,264,262,268,260,260,264,262,260,260,268,272,264,262,258,268,270,268,272,280,266,270,262,278,282,280,268,268,268,280,274,292,286,292,276,290,296,292,286,290,290,290,288,284,290,282,282,278,290,280,290,286,284,284,292,286,290,298,298,310,302,292,298,296,306,292,286,284,274,274,274,276,272,280,274,276,278,280,284,290,280,272,280,286,284,276,272,284,280,274,270,278,280,286,284,286,286,282,282,286,280,290,274,284,272,274,274,266,270,270,276,272,272,266,264,262,278,272,268,274,278,270,278,266,276,274,272,266,278,264,272,258,272,274,266,266,276,272,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,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8]';
H=length(height)/steps;
alpha2=zeros(H,steps);
radius2=zeros(H,steps);
height2=zeros(H,steps);
g=zeros(H,steps);
alpha3=zeros(H,steps+1);
radius3=zeros(H,steps+1);
height3=zeros(H,steps+1);
p=0.95;
xxi=(0:2*pi/steps:(2*pi-(2*pi/steps)));
for i=1:H
for j=1:steps
alpha2(i,j)=alpha(j+(i-1)*steps,1);
radius2(i,j)=radius(j+(i-1)*steps,1);
height2(i,j)=height(j+(i-1)*steps,1);
end
end
for i=1:1:H
g(i,:)=csaps(alpha2(i,:), radius2(i,:), p, xxi);
end
alpha3(:,steps+1)=alpha2(:,1);
radius3(:,steps+1)=g(:,1);
height3(:,steps+1)=height2(:,1);
for i=1:H
for j=1:steps
alpha3(i,j)=alpha2(i,j);
radius3(i,j)=g(i,j);
height3(i,j)=height2(i,j);
end
end
[x,y,z]=pol2cart(alpha3,radius3,height3);
surf (x,y,z)
hold on
%fill3(x(size(z,1),:,:), y(size(z,1),:,:),z(size(z,1),:,:),'r');
%fill3(x(1,:,:), y(1,:,:),z(1,:,:),'k');
%Dosen't work with surf2stl, becaus I can not transform it in suitable
%coordinates!
surf2stl('test.stl',x,y,z);
1 个评论
Karim
2022-7-8
Can you add the 'census' file? You can use the paperclib button to add files to your question.
回答(1 个)
Yash
2024-3-15
Hi Simon,
As I can understand, you want to create a closed body from your 3D scan data that includes a bottom and a lid, and is suitable for conversion to STL format. Since "surf2stl" works by converting surface data to STL format, we'll need to ensure that the surface data includes the bottom and lid of your object. Here's an approach that might help:
1. Create Bottom and Lid Surfaces
Given that you have the x, y, and z matrices from your scanning process, you'll need to manually create the bottom and lid for your object. The bottom can be created by taking the lowest z values and creating a surface that spans the boundary of your object at this z level. Similarly, the lid can be created by taking the highest z values.
% Find the boundary of the object
minZ = min(z(:));
maxZ = max(z(:));
% Assuming the object's boundary points at the bottom and top can be reused
% Create bottom surface
bottomX = x(1, :); % Adjust according to your object's structure
bottomY = y(1, :); % Adjust according to your object's structure
bottomZ = repmat(minZ, size(bottomX)); % Flat bottom at minZ
% Create lid surface
lidX = x(end, :); % Adjust according to your object's structure
lidY = y(end, :); % Adjust according to your object's structure
lidZ = repmat(maxZ, size(lidX)); % Flat lid at maxZ
2. Concatenate Surfaces
Once you have created the bottom and lid, you'll need to concatenate these with your existing surface data. This involves creating new x, y, and z matrices that include the points for the bottom, the main body, and the lid of your object.
% Concatenate the original and new surfaces
newX = [bottomX; x; lidX];
newY = [bottomY; y; lidY];
newZ = [bottomZ; z; lidZ];
3. Visualize the New Object
% Plot the new object to check
figure;
surf(newX, newY, newZ);
4. Export to STL
% Finally, use surf2stl with the new concatenated surfaces
surf2stl('closed_body_test.stl', newX, newY, newZ);
Considerations:
- Complex Shapes: If your object has a complex shape where the bottom or lid cannot be easily represented as a flat surface, you'll need a more sophisticated approach to generate these surfaces based on the object's boundary.
- Holes and Overhangs: If the object has holes or overhangs, ensure that the bottom and lid do not inadvertently fill these features inappropriately.
Hope this helps!
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!