[Scilab-users] Scilab and gmsh to plot surfaces

Carrico, Paul paul.carrico at auxitrolweston.com
Thu Jun 27 15:50:23 CEST 2019


Dear All

After a tesselation using cgal library (delaunay_2), I used gmsh (http://gmsh.info/) to plot the triangles ... just an idea of sharing about 2 powerful tools :-)
(useful with a huge amount of nodes)

A basic "saddle" surface has been used to test it

Hope it help

Paul

###############################################################################
clc, mode(0), clear

PATH = get_absolute_file_path("saddle.sce");
fich = mopen(PATH + "/saddle.msh","w");

// saddle surface
function [z]=saddle(x, y)
    z = x^2 - y^2
endfunction

n = 100;
x = linspace(-2,2,n)'; // (n,1) matrix
y = linspace(-1,3,n)'; // (n,1) matrix

i = (1:n)'; j = ones(n,1);
X = x .*. j;
Y = j .*. y;
Z = saddle(X,Y);

// ### plot in gmsh ###
// Surface number
SurfaceNumber = 1;

//tri = delaunay_2(X,Y);
triangles = delaunay_2(X',Y');
NumberOfTriangles = size(triangles,"r");

mfprintf(fich,"$MeshFormat\n");
mfprintf(fich,"2.2 0 8\n");
mfprintf(fich,"$EndMeshFormat\n");
// Nodes
mfprintf(fich,"$Nodes\n");
mfprintf(fich,"%d\n",n*n);
i = (1:n*n)';
mfprintf(fich,"%d %g %g %g\n",i,X(i),Y(i),Z(i));
mfprintf(fich,"$EndNodes\n");

// elements
mfprintf(fich,"$Elements\n")
mfprintf(fich,"%d\n",NumberOfTriangles);
i = (1 : NumberOfTriangles)';
SurfaceNumber = SurfaceNumber*ones(NumberOfTriangles,1);
mfprintf(fich,"%d 2 2 %d %d %d %d %d\n",i,SurfaceNumber,SurfaceNumber,triangles(i,1),triangles(i,2),triangles(i,3));
mfprintf(fich,"$EndElements\n")
mclose(fich);

// ### plot in scilab ###
scf(0);
drawlater();
f = gcf();
f.figure_size = [1000, 1000];
f.background = color(255,255,255);
a = gca();
a.font_size = 2;
a.x_label.text = '$X$';
a.x_label.font_size = 4;
a.y_label.text = '$Y$';
a.Y_label.font_size = 4;
a.z_label.text = "$\sigma$";
a.z_label.font_size = 4;
plot3d(x, y, feval(x, y, saddle));
drawnow();

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.scilab.org/pipermail/users/attachments/20190627/d466e28c/attachment.htm>


More information about the users mailing list