[scilab-Users] equivalent for Matlab patch() in Scilab?

Yann Collette yann.collette at scilab.org
Thu Sep 24 22:16:14 CEST 2009


Here is the examples of the plot3d help page:

// The plot3d function to draw patches:
// patch(x,y,[z])
// patch(x,y,[list(z,c)])
// The size of x : number of points in the patches x number of patches
// y and z have the same sizes as x
// c:
// - a vector of size number of patches: the color of the patches
// - a matrix of size number of points in the patches x number of
//   patches: the color of each points of each patches

// Example 1: a set of triangular patches

x = [0 0;
     0 1;
     1 1];

y = [1 1;
     2 2;
     2 1];

z = [1 1;
     1 1;
     1 1];

tcolor = [2 3]';

subplot(2,2,1);
plot3d(x,y,list(z,tcolor));
xtitle('A triangle set of patches');

// Example 2: a mixture of triangular and quadrangular patches

xquad = [5, 0;
         10,0;
         15,5;
         10,5];
        
yquad = [15,0;
         20,10;
         15,15;
         10,5];
        
zquad = ones(4,2);

xtri = [ 0,10,10, 5, 0;
        10,20,20, 5, 0;
        20,20,15,10,10];
       
ytri = [ 0,10,20, 5,10;
        10,20,20,15,20;
         0, 0,15,10,20];
        
ztri = zeros(3,5);

subplot(2,2,3);
plot3d(xquad,yquad,zquad);
plot3d(xtri,ytri,ztri);
xtitle('Mixing triangle and quadrangle set of patches');

// Example 3: some rabbits

rabxtri = [ 5,  5, 2.5,  7.5, 10;
            5, 15, 5,   10,   10;
           15, 15, 5,   10,   15];
          
rabytri = [10, 10, 9.5,  2.5, 0;
           20, 10, 12,   5,   5;
           10   0   7    0    0];
rabztri = [0,0,0,0,0;
           0,0,0,0,0;
           0,0,0,0,0];

rabtricolor_byface = [2 2 2 2 2];

rabtricolor = [2,2,2,2,2;
               3,3,3,3,3;
               4,4,4,4,4];
              
rabxquad = [0, 1;
            0, 6;
            5,11;
            5, 6];
           
rabyquad = [18,23;
            23,28;
            23,28;
            18,23];
           
rabzquad = [1,1;
            1,1;
            1,1;
            1,1];

rabquadcolor_byface = [2 2];

rabquadcolor = [2,2;
                3,3;
                4,4;
                5,5];

subplot(2,2,2);
plot3d(rabxtri, rabytri, list(rabztri,rabtricolor));
plot3d(rabxquad,rabyquad,list(rabzquad,rabquadcolor));
h = gcf();
h.children(1).background = 1;
xtitle('A psychedelic rabbit set of patches');

subplot(2,2,4);
plot3d(rabxtri, rabytri, list(rabztri,rabtricolor_byface));
plot3d(rabxquad,rabyquad,list(rabzquad,rabquadcolor_byface));
h = gcf();
h.children(1).background = 1;
xtitle('A standard rabbit set of patches');




// Vertex / Faces example: 3D example

// The vertex list contains the list of unique points composing each patch
// The points common to 2 patches are not repeated in the vertex list

vertex = [0 1 1;
          0 2 2;
          1 2 3;
          1 1 4];

// The face list indicates which points are composing the patch.       
face = [1 2 3;
        1 3 4];

tcolor = [2 3]';
        
// The formula used to translate the vertex / face representation into 
x, y, z lists

xvf = 
matrix(vertex(face,1),size(face,1),length(vertex(face,1))/size(face,1))';
yvf = 
matrix(vertex(face,2),size(face,1),length(vertex(face,1))/size(face,1))';
zvf = 
matrix(vertex(face,3),size(face,1),length(vertex(face,1))/size(face,1))';

scf();
subplot(2,1,1);
plot3d(xvf,yvf,list(zvf,tcolor));
xtitle('A triangle set of patches - vertex / face mode - 3d');

// 2D test
// We use the 3D representation with a 0 Z values and then switch to 2D 
representation

// Vertex / Faces example: 3D example

// The vertex list contains the list of unique points composing each patch
// The points common to 2 patches are not repeated in the vertex list

vertex = [0 1;
          0 2;
          1 2;
          1 1];

// The face list indicates which points are composing the patch.       
face = [1 2 3;
        1 3 4];
        
// The formula used to translate the vertex / face representation into 
x, y, z lists

xvf = 
matrix(vertex(face,1),size(face,1),length(vertex(face,1))/size(face,1))';
yvf = 
matrix(vertex(face,2),size(face,1),length(vertex(face,1))/size(face,1))';
zvf = 
matrix(zeros(vertex(face,2)),size(face,1),length(vertex(face,1))/size(face,1))';

subplot(2,1,2);
plot3d(xvf,yvf,list(zvf,tcolor));
xtitle('A triangle set of patches - vertex / face mode - 2D');
a = gca();
a.view = '2d';



Yann Collette a écrit :
> Michel Audette a écrit :
>> Dear Scilab users,
>>
>> can someone indicate to me if there is an equivalent to the Matlab 
>> patch() function in Scilab?
>>
>> Thank you for your kind consideration.
>>
>> Best wishes,
>>
>> Michel
>>
>> -- 
>> Michel Audette, Ph.D.
>> R & D Engineer,
>> Kitware Inc.,
>> Chapel Hill, N.C.
>>
> Hello,
>
> Yes, plot3d can do the same things as patch.
> If you have access to a nightly build, do a "help plot3d". There are 2 
> examples of use of plot3d like patch:
> - a simple plot3d with a X,Y,Z
> - a plot3d with faces and vertex.
>
> YC




More information about the users mailing list