gtsam/matlab/gtsam_examples/cylinderSampling.m

25 lines
711 B
Matlab
Raw Normal View History

function [cylinder] = cylinderSampling(baseCentroid, radius, height, density)
2015-01-07 22:56:18 +08:00
%
import gtsam.*
% calculate the cylinder area
area = 2 * pi * radius * height;
2015-01-07 22:56:18 +08:00
pointsNum = round(area * density);
2015-01-07 22:56:18 +08:00
points3 = cell(pointsNum, 1);
2015-01-07 22:56:18 +08:00
% sample the points
for i = 1:pointsNum
2015-01-07 22:56:18 +08:00
theta = 2 * pi * rand;
x = radius * cos(theta) + baseCentroid.x;
y = radius * sin(theta) + baseCentroid.y;
2015-01-07 22:56:18 +08:00
z = height * rand;
points3{i,1} = Point3([x,y,z]');
2015-01-07 22:56:18 +08:00
end
cylinder.area = area;
cylinder.radius = radius;
cylinder.height = height;
cylinder.Points = points3;
cylinder.centroid = Point3(baseCentroid.x, baseCentroid.y, height/2);
2015-01-07 22:56:18 +08:00
end