Javier de la Rica
Javier de la Rica

Reputation: 45

Plot sphere containing a 3d point cloud in Matlab

I have a three-dimensional point cloud saved in a PLY file.

Taking a point (x, y, z) as the center of the sphere, I want to plot the whole point cloud, but with a sphere of radius R which contains several points of the point cloud, but not all the cloud.

The sphere shpould be quite transparent to let the points inside itself visible.

I have tried the following with no success:

% Read point cloud file
ptCloud = pcread('frame0000.ply');
% Show point cloud
pcshow(ptCloud);
hold on

% Sphere generation
[x, y, z] = sphere;
surf(x,y,z)
hold on 
% Sphere centered at (3, -2, 0)
surf(x+3,y-2,z) 

Doing this, I get a plot with a sphere centered at (3, -2, 0), but it takes ALL the pointcloud inside the sphere. What's more, I cannot see the point cloud as the sphere is opaque.

How can I give a specific radius to the sphere so that it only takes the points within that radius R? And, how can I make the sphere transparent but not invisible, so that the points within the sphere are visible?

I appreciate all answers! 😊

Upvotes: 3

Views: 752

Answers (1)

Nakini
Nakini

Reputation: 772

There are two things:

  1. Creating a sphere -- Using the Matlab function sphere, you could create a unit sphere. If you want to shrink/enlarge, you could multiply the x, y, and z s' with a scalar. Make sure you do that before shifting the origin. After that, you could shift the origin.

  2. Plotting the sphere and manipulating the properties of the plot -- Here, you can change the properties of the figure to make it transparent. There are various options which could be found at Surface Properties.

Example:

[x, y, z] = sphere;
mesh(3*x+3,3*y-2,3*z, 'Marker', '.', 'EdgeColor', 'flat', 'FaceColor', 'none', 'LineStyle', ':')
hold on;
plot3(3, -2, 0, '+r', 'MarkerSize', 20)

Upvotes: 4

Related Questions