Plotting a color function on a sphere
조회 수: 5 (최근 30일)
이전 댓글 표시
Dear kind helpers,
I have a question which I have not been able to resolve yet.
I have three vectors x, y and z with x(i), y(i) and z(i) giving a point on the unit sphere. I also have a fourth vector c of the same length as x,y and z containing function values, where c(i) corresponds to the function value at the point (x(i), y(i), z(i)) on the sphere.
I want to make a contour plot of the function c(i) on the sphere defined by all the points (x(i), y(i), z(i)). How can I do such a thing?
Best wishes,
Pablo
댓글 수: 0
답변 (2개)
Walter Roberson
2011년 6월 19일
The following will not be a contour plot as such, but it might serve your purpose:
pointsize = 8;
scatter3(x,y,z,pointsize,c)
If you want something closer to a contour plot, you could use histc() or interp1() to effectively quantize the c values and pass the quantized values in to scatter3 instead of c itself.
Patrick Kalita
2011년 6월 21일
There are a couple of avenues to explore. I wouldn't say either of them are particularly easy, unfortunately.
Idea 1: Use contourslice. The idea here would be that you'd first have to interpolate your scattered data c onto a uniform 3D grid (e.g. using meshgrid and TriScatteredInterp). Then you'd pass the gridded x, y, z, and c to contourslice along with 2D arrays Xi, Yi, Zi that define the surface of a sphere where the contours will lie.
Idea 2: Turn your x, y, and z data into spherical coordinates (using cart2sph). Then you can compute the contours in the 2D theta-phi space using contourc. The output of contourc will also be in terms of theta and phi. You can transform back into Cartesian coordinates with sph2cart (the radius being 1 at every point). Finally you can manually draw the contours with the resulting x, y, and z coordinates.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Surface and Mesh Plots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!