Let a surface defined by 3 nodes: [P1,P2,P3]. Then you must cycle clockwise trough theses nodes to have the right orientation of inside and outside. Here is a drawing explaining it:
3 of your polygones are defined conterclockwise, thoses with y=1, y=3 and x = 1. When drawing 4 points polygones, to switch the rotation from clockwise to counterclockwise, just swap the 2nd and 4th nodes or 1st and 3rd.
Thus you must set your points as:
xx = [[2;2;1;3;],[2;2;3;3],[2;2;3;1],[2;2;1;1],[1;1;3;3],[3;3;3;3],[3;3;1;1],[1;1;1;1],[1;2;2;3],[1;1;2;2],[3;2;2;3],[3;2;2;1]]
yy = [[2;2;1;1;],[2;2;1;3],[2;2;3;3],[2;2;3;1],[1;1;1;1],[1;1;3;3],[3;3;3;3],[3;3;1;1],[1;2;2;1],[1;3;2;2],[1;2;2;3],[3;2;2;3]]
zz = [[0;0;1;1;],[0;0;1;1],[0;0;1;1],[0;0;1;1],[1;2;2;1],[1;2;2;1],[1;2;2;1],[1;2;2;1],[2;3;3;2],[2;2;3;3],[2;3;3;2],[2;3;3;2]]
This will give the desired output :
Scilab 6.0.0 bug
In this version, if your surfaces are parallel to the cartesian axes, then Scilab will direct it along the axis, no matter how you defined it. Thus your problem. A workaround could be to offset one of the coordinate by a small delta, which must be not too small, as shown in below example.
Regarding your problem, if we want to keep the geometry of your object, we could tilt it with a tiny angle: using rotation matrix, if the computational cost induced by the rotation of all the coordinates doesn't bother you. Here's your script with the tilted object
clc
clear
xdel(winsid())
xx = [[2;2;1;3;],[2;2;3;3],[2;2;3;1],[2;2;1;1],[1;1;3;3],[3;3;3;3],[3;3;1;1],[1;1;1;1],[1;2;2;3],[1;1;2;2],[3;2;2;3],[3;2;2;1]]
yy = [[2;2;1;1;],[2;2;1;3],[2;2;3;3],[2;2;3;1],[1;1;1;1],[1;1;3;3],[3;3;3;3],[3;3;1;1],[1;2;2;1],[1;3;2;2],[1;2;2;3],[3;2;2;3]]
zz = [[0;0;1;1;],[0;0;1;1],[0;0;1;1],[0;0;1;1],[1;2;2;1],[1;2;2;1],[1;2;2;1],[1;2;2;1],[2;3;3;2],[2;2;3;3],[2;3;3;2],[2;3;3;2]]
col = ones(12,1)*3
figure(1)
set(gcf(),'background',-2)
subplot(2,1,1)
plot3d(xx,yy,list(zz,col))
title('Object with surfaces orthogonal to cartesian axis')
subplot(2,1,2)
// t is angle in radian showing the tilt
t = %pi/10000
c = cos(t)
s = sin(t)
rot = [1,0,0;0,c,-s;0,s,c]*[c,0,s;0,1,0;-s,0,c]*[c,-s,0;s,c,0;0,0,1]
for i=1:size(xx,1)
for j = 1:size(xx,2)
xyz=(rot*[xx(i,j);yy(i,j);zz(i,j)])
x(i,j)=xyz(1)
y(i,j)=xyz(2)
z(i,j)=xyz(3)
end
end
plot3d(x,y,list(z,col))
title('Object with surfaces tildted by an angle of '+string(t)+' rad')
Script showing 2 surfaces defined by the same nodes but in opposite order.
clc
clear
xdel(winsid())
figure(1)
set(gcf(),'background',-2)
cr=color('red') // color of the outside surface
P1 = [0,0,0] //
P2 = [0,1,0]
P3 = [1,0,0]
F1 = [P1;P2;P3] // defining surface clockwise
F2 = [P1;P3;P2] // counterclockwise
subplot(2,2,1)
plot3d(F1(:,1),F1(:,2),list(F1(:,3),cr*ones(F1(:,3))))
xstring(F1(:,1),F1(:,2),['P1','P2','P3'])
title('surface is [P1,P2,P3] with z_P3=0')
set(gca(),'data_bounds',[0,1,0,1,-1,1])
subplot(2,2,2)
plot3d(F2(:,1),F2(:,2),list(F2(:,3),cr*ones(F2(:,3))))
xstring(F2(:,1),F2(:,2),['P1','P3','P2'])
title('surface is [P1,P3,P2] with z_P3=0, broken with Scilab 6.0.0')
set(gca(),'data_bounds',[0,1,0,1,-1,1])
subplot(2,2,3)
plot3d(F2(:,1),F2(:,2),list(F2(:,3)+[0;0;10^-7],cr*ones(F2(:,3))))
xstring(F2(:,1),F2(:,2),['P1','P3','P2'])
title('surface is [P1,P3,P2] with |z_P3| < 10^-8')
set(gca(),'data_bounds',[0,1,0,1,-1,1])
subplot(2,2,4)
plot3d(F2(:,1),F2(:,2),list(F2(:,3)+[0;0;10^-8],cr*ones(F2(:,3))))
xstring(F2(:,1),F2(:,2),['P1','P3','P2'])
title('surface is [P1,P3,P2] with |z_P3| = 10^-8, broken in 6.0.0')
set(gca(),'data_bounds',[0,1,0,1,-1,1])
Scilab 5.5.1
Scilab 6.0.0