1

i'd like to draw sphere using 'patch' function in Matlab.

in function 'patch' "vertex=[~~]" in this part, how to choice the point...

And i wonder if possible to draw sphere using 'patch function'..

please help!

jeong
  • 13
  • 2

1 Answers1

3

Assume you have coordinates for points on the sphere in x, y, and z, as obtained by

[x,y,z] = sphere;

Then faces and vertices of a patch object can be obtained using surf2patch:

fvc = surf2patch(x,y,z);

Finally, it can be plotted:

patch('Faces', fvc.faces, 'Vertices', fvc.vertices, 'FaceColor', [1, 0, 0])

This approach can be generalized to any function data.

zeeMonkeez
  • 5,057
  • 3
  • 33
  • 56
  • 2
    Just as extra, you don't even need to separate the values, you can pass fvc structure directly to `patch` as `patch(fvc,'FaceColor',[1,0,0])` – Noel Segura Meraz Feb 01 '16 at 05:26
  • so good information !! and..why don't need to separate the values..? – jeong Feb 01 '16 at 15:24
  • @jeong That's what is referred to as [`patch(S)`](http://uk.mathworks.com/help/matlab/ref/patch.html#busd9x8-1) in the documentation. – zeeMonkeez Feb 01 '16 at 15:33
  • @zeeMonkeez First so sorry i using this program first..if i use vector, can i draw sphere? same as using patch.... i want to fix center point and there is a constant distance from the center. – jeong Feb 01 '16 at 15:55
  • @jeong take a look at [`sphere`](http://uk.mathworks.com/help/matlab/ref/sphere.html). The generated sphere has radius 1, so you can just scale the coordinates to match the length of your vector. The examples show how to move the sphere in space. – zeeMonkeez Feb 01 '16 at 16:00