How to plot a list of vectors as a sphere?

2019-05-26 06:21发布

I have an array of normalized vectors (1538 of them) forming a sphere. Also I has an array of numbers of the same size 1538. I want to plot something like this:

enter image description here

I tried the sphere and surf functions but I can't find a way to use my vectors. I figured there should be some way to do this.

Thanks a lot.

1条回答
再贱就再见
2楼-- · 2019-05-26 07:04

I think you can use delaunay to create a triangulation and plot that using trimesh or trisurf.

Both trimesh as trisurf accepts a fourth argument to specify the color of each vertex, add the option 'facecolor','interp' to interpolate the color of each face between vertices.

edit: I experimented a bit further on it, and since it's a sphere, I think convhull is better suited.

Example:

[x,y,z]=sphere(25);
x=x(:);y=y(:);z=z(:);

tri = convhull([x y z]);
C = cos(y);
trisurf(tri,x,y,z,C,'facecolor','interp');

trisurf_colored

instead of C in the example you can use your own vector of values to specify the color

查看更多
登录 后发表回答