03.18.08
Disegnare una superficie parametrica con Scilab / Draw a parametric surface with Scilab
Questo articolo sarà sia in Italiano che in Inglese: scusate per gli strani colori ma aiuta a distinguere tra le due lingue.
Mi serviva per la tesi produrre delle superfici parametriche utilizzando Scilab, tutti gli esempi trovati nel manuale e su web non funzionavano e davano strani errori!!!! Così mi sono stufato e ho studiato un metodo alternativo per disegnarle…
Per disegnare una sfera parametrica (di prova) ho seguito il metodo suggerito dalle guide ricevendo l’errore che vedete:
This article will be either in Italian and in English: sorry for the weird colors but help to differentiate them.
I was in trying to plot a 3d parametric surface with Scilab, all the example I’ve found in the manual and on the web doesn’t worked for me giving some weird errors!!!! So i pissed off and worked around it finding my own way to draw a parametric surface…
To draw a parametric sphere (to test) I tried the way suggested by manuals getting the error you see:
u=linspace(0,%pi);// primo vettore dei parametri / first parameter vector
v=linspace(0,2*%pi);// secondo vettore dei parametri / second parameter vector
deff('[x,y,z]=fun(u,v)’,['x=sin(u).*cos(v)','y=sin(u).*cos(v)','z=cos(u)']);// definizione dell’equazione parametrica / define the parametric equation
mesh(u,v,fun);Z must not be a scalar or vector, not rendering surface.
!–error 999
set: color_mode property does not exist for this handle
at line 4 of function generic_i_h called by :
line 2 of function %s_i_h called by :
line 22 of function mesh called by :
mesh(u,v,fun);
Ho ricontrollato parecchie volte ma non ho fatto nulla di diverso da quello consigliato in numerose guide! Eppure non funziona così… Quindi ecco come ho risolto:
I checked a lot of times but exactly made what many guides advice to do! Nevertheless it doesn’t work this way… So here how i solved this issue:
Ho creato manualmente le X,Y,Z richieste dalle funzioni plot3d, mesh e surf come segue.
I manually created the X,Y,Z needed by plot3d, mesh and surf function as follows.
u=linspace(0,%pi)';// primo vettore COLONNANx1dei parametri / first parameterNx1COLUMN vector
v=linspace(0,2*%pi);// secondo vettore RIGA1xNdei parametri / second parameter1xNROW vector
[si,sj]=size(v);// mi salvo le dimensioni del vettore v che mi serviranno dopo / I store the size of the v vector because i will need them
X=sin(u)*cos(v);// calcolo la matrice XNxN/ I compute the XNxNmatrix
Y=sin(u)*sin(v);// calcolo la matrice YNxN/ I compute the YNxNmatrix
Z=cos(u)*ones(si,sj);// calcolo la matrice ZNxN, nota che tutte le colonne della matrice sono identiche / I compute the ZNxNmatrix, note that all the columns of the matrix are the same
plot3d(X,Y,Z);// disegno, potrei usare anchemeshosurf/ plotting, you can use eithermeshorsurftoo
Se non capite cos’ho fatto forse con questo vi sarà più chiaro:
- un vettore
Nx1per un vettore1xMformano una matriceNxM. Quindisin(u)*cos(v)è una matriceNxNin questo caso. L’ordine dei moltiplicandi È importante. - X,Y e Z devono essere matrici tutte della stessa dimensione.
- la funzione
ones(righe,colonne)restituisce una matrice (o un vettore) di tutti “uni” con dimensionerigheXcolonne: possiamo usarla quando ad una delle funzioni manca un parametro. Per la sfera ad esempio costruendo la Z utilizziamo un vettore di tutti “uni” al posto di v che manca. - potete utilizzare
linspace(inizio,fine,dimensione)per creare gli array oppure anche[inizio:passo:fine]a vostro piacimento. I 2 vettori dei parametri possono avere dimensioni diverse ma il primo dev’essere un vettore colonna e il secondo un vettore riga per creare delle matrici. - In altre situazioni semplicemente ragionate secondo le regole matriciali.
If you can’t understand what i made read below:
- if you multiply an
Nx1vector with a1xMvector you get anNxMmatrix. Thussin(u)*cos(v)is anNxNmatrix in this example. The multiplier order DOES matter. - X,Y e Z must all be matrix of the same dimension.
- the
ones(rows,columns)function return a matrix (or a vector) full of “ones” ofrowsXcolumnsdimension: you can use it when you miss a parameter in one of the functions or when you miss both them. For this example we use a vector with all “ones” instead of the missing v to compute Z. - you can use either
linspace(start,end,size)either[start:step:end]as you like to create the parameters vectors. The 2 parameters vector can be of different size as long as the first is a column vector and the seconds a row one or you will not be able to create those matrix. - On other situation simply think with the matrix rules.





Arcimboldo detto,
21 Giugno, 2008 a 23:10
diamine un modo *semplice* non esiste ?
mastro detto,
22 Giugno, 2008 a 13:52
@arcimboldo
per “semplice” cosa intendi?
da che mi risulta con altri software (matlab) non è che cambi così tanto…
salvo l’esportazione dell’immagine che in scilab è effettivamente fatta maluccio