How to convert matlab plot figure into stl file ? Further I Want to use it for my uav scenario .

3 views (last 30 days)
I created a scenario for uav trajectory testing but now i am unable to import the scenario file to my UAV scenario designer .
Here is the code for reference :
scene = uavScenario("UpdateRate", 200 , "StopTime", 2, "ReferenceLocation",[46,42,0]);
>> scene.addInertialFrame("ENU", "MAP", trvec2tform([1 0 0]));
>> scene.addMesh("Polygon",{[-100 0; 100 0; 100 100; -100 100],[-5 0]},[0.3 0.3 0.3]);
>> scene.addMesh("Cylinder",{[20 10 10],[0 30]},[0 1 0]);
>> scene.addMesh("Cylinder",{[46 42 5],[0 20]},[0 1 0],"UseLatLon" , true);
>> traj = waypointTrajectory("Waypoints", [0 -20 -5; 20 -20 -5; 20 0 -5],"TimeOfArrival",[0 1 2]);
>> uavPlat = uavPlatform("UAV",scene,"Trajectory",traj);
>> updateMesh(uavPlat,"quadrotor", {4}, [1 0 0],eul2tform([0 0 pi]));
>> addGeoFence(uavPlat,"Polygon", {[-50 0; 50 0; 50 50; -50 50],[0 100]},true,"ReferenceFrame","ENU");
>> insModel = insSensor();
>> ins = uavSensor("INS",uavPlat,insModel,"MountingLocation",[4 0 0]);
>> ax = show3D(scene);
>> axis(ax,"equal");
>> setup(scene);
>> while advance(scene)
% Update sensor readings
updateSensors(scene);
% Visualize the scenario
show3D(scene,"Parent",ax,"FastUpdate",true);
drawnow limitrate
end
>> addCustomTerrain("CustomTerrain","n39_w106_3arc_v2.dt1");
>> scenario = uavScenario("ReferenceLocation", [39.5 -105.5 0]);
>> addMesh(scenario,"terrain", {"CustomTerrain", [-200 200], [-200 200]}, [0.6 0.6 0.6]);
>> show3D(scenario);
>> buildingCenters = [-50, -50; 100 100];
>> buildingHeights = [30 100];
>> buildingBoundary = [-25 -25; -25 50; 50 50; 50 -25];
>> for idx = 1:size(buildingCenters,1)
buildingVertices = buildingBoundary+buildingCenters(idx,:);
buildingBase = min(terrainHeight(scenario,buildingVertices(:,1),buildingVertices(:,2)));
addMesh(scenario,"polygon", {buildingVertices, buildingBase+[0 buildingHeights(idx)]}, [0.3922 0.8314 0.0745]);
end
>>
show3D(scenario);
>> view([0 ,15])
>> removeCustomTerrain("CustomTerrain")

Answers (1)

Nadia Shaik
Nadia Shaik on 22 Nov 2022
Hi Karnvir,
I understand that you want to convert mesh data to 'STL' file. To achieve this, you can download some STL file conversion tools from File Exchange:
For example:
etc.
I hope this helps.
  1 Comment
DGM
DGM on 29 Jun 2025
Edited: DGM on 29 Jun 2025
MATLAB has had STL read/write tools since R2018b
I don't know anything about these UAV toolbox tools, so I don't know how easy it is to get the displayed content into an acceptable form for export.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!