# Creating and exporting surface from points

**URL:** <https://scilab.discourse.group/t/creating-and-exporting-surface-from-points/115>\
**Category:** Graphics and plotting\
**Created:** [July 12, 2023, 10:43am UTC](https://scilab.discourse.group/t/creating-and-exporting-surface-from-points/115 "2023-07-12T10:43:21Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Look4nurns](https://avatars.discourse-cdn.com/v4/letter/l/b487fb/32.png) [@Look4nurns](https://scilab.discourse.group/u/Look4nurns)\
**Post date:** [July 12, 2023, 10:43am UTC](https://scilab.discourse.group/t/creating-and-exporting-surface-from-points/115/1 "2023-07-12T10:43:21Z")

</div>

Hello  
I have created a scilab file where I put in different layer points coordinate.  
now I’d like to create a surface from all this layer and then export it.

How can I do?

thnaks  
sergio

---

<div class="post-metadata">

**Author:** ![mottelet](https://yyz2.discourse-cdn.com/free1/user_avatar/scilab.discourse.group/mottelet/32/13_2.png) [@mottelet](https://scilab.discourse.group/u/mottelet)\
**Post date:** [July 12, 2023, 11:30am UTC](https://scilab.discourse.group/t/creating-and-exporting-surface-from-points/115/2 "2023-07-12T11:30:48Z")

</div>

Hello Sergio,

Is the distribution of points structured in some way, or completely unstructured ?

S.

---

<div class="post-metadata">

**Author:** ![Look4nurns](https://avatars.discourse-cdn.com/v4/letter/l/b487fb/32.png) [@Look4nurns](https://scilab.discourse.group/u/Look4nurns)\
**Post date:** [July 12, 2023, 12:17pm UTC](https://scilab.discourse.group/t/creating-and-exporting-surface-from-points/115/3 "2023-07-12T12:17:26Z")

</div>

I’ve created a matrix of points  
Each row have coordinates x,y,z of the points  
each row same points number

it’s enough for you?

---

<div class="post-metadata">

**Author:** ![mottelet](https://yyz2.discourse-cdn.com/free1/user_avatar/scilab.discourse.group/mottelet/32/13_2.png) [@mottelet](https://scilab.discourse.group/u/mottelet)\
**Post date:** [July 12, 2023, 12:25pm UTC](https://scilab.discourse.group/t/creating-and-exporting-surface-from-points/115/4 "2023-07-12T12:25:31Z")

</div>

> [@Look4nurns](#):
>
> Each row have coordinates x,y,z of the points  
> each row same points number

Can you be more precise ? Is the matrix of size n by 3 ? What do you mean by “each row same points number” ? Can you share your file here ?

S.

---

<div class="post-metadata">

**Author:** ![Look4nurns](https://avatars.discourse-cdn.com/v4/letter/l/b487fb/32.png) [@Look4nurns](https://scilab.discourse.group/u/Look4nurns)\
**Post date:** [July 12, 2023, 3:18pm UTC](https://scilab.discourse.group/t/creating-and-exporting-surface-from-points/115/5 "2023-07-12T15:18:23Z")

</div>

Hi  
I can send you in a private way or put here only a part of it (where the matrix is created)  
[esempio.sod](https://scilab.discourse.group/uploads/short-url/gwccfCqnu2gcCkEJEA0Fj6eMXrz.sod) (9.8 KB)

---

<div class="post-metadata">

**Author:** ![mottelet](https://yyz2.discourse-cdn.com/free1/user_avatar/scilab.discourse.group/mottelet/32/13_2.png) [@mottelet](https://scilab.discourse.group/u/mottelet)\
**Post date:** [July 12, 2023, 3:23pm UTC](https://scilab.discourse.group/t/creating-and-exporting-surface-from-points/115/6 "2023-07-12T15:23:27Z")

</div>

Edit your previous post : you can save the matrix in a sod file, i.e. `save data.sod A` and drag and drop the file in the editing window.

S.

---

<div class="post-metadata">

**Author:** ![mottelet](https://yyz2.discourse-cdn.com/free1/user_avatar/scilab.discourse.group/mottelet/32/13_2.png) [@mottelet](https://scilab.discourse.group/u/mottelet)\
**Post date:** [July 12, 2023, 4:40pm UTC](https://scilab.discourse.group/t/creating-and-exporting-surface-from-points/115/7 "2023-07-12T16:40:26Z")

</div>

I meant only the resulting matrix. You sent the whole Scilab script (which doesn’t run because some matrices are not defined). So, please save the matrix you were talking about in a .sod file.

S.

---

<div class="post-metadata">

**Author:** ![Look4nurns](https://avatars.discourse-cdn.com/v4/letter/l/b487fb/32.png) [@Look4nurns](https://scilab.discourse.group/u/Look4nurns)\
**Post date:** [July 13, 2023, 6:58am UTC](https://scilab.discourse.group/t/creating-and-exporting-surface-from-points/115/8 "2023-07-13T06:58:48Z")

</div>

Hi  
Ok is easier if I give you the all file because I don’t have only the matrix.  
You need also the txt file in the same folder  
[test\_surf.sod](https://scilab.discourse.group/uploads/short-url/fJaUq5lRWdZRnnzaTdnZcUgpDV8.sod) (21.1 KB)  
[Import\_Mat\_Rad\_Chord\_Gam\_Camb\_thick\_P.sod](https://scilab.discourse.group/uploads/short-url/cDn7ONlgf8t84dRXdsyLdOzaAhB.sod) (650 Bytes)

---

<div class="post-metadata">

**Author:** ![mottelet](https://yyz2.discourse-cdn.com/free1/user_avatar/scilab.discourse.group/mottelet/32/13_2.png) [@mottelet](https://scilab.discourse.group/u/mottelet)\
**Post date:** [July 13, 2023, 7:10am UTC](https://scilab.discourse.group/t/creating-and-exporting-surface-from-points/115/9 "2023-07-13T07:10:04Z")

</div>

Hello,

What do you want to do exactly ? Your script already draws a (very folded) surface. Would a STL format export be OK for you ? What is the `RA_X2P_Imp2_TraslRot1.ibl` file ?

---

<div class="post-metadata">

**Author:** ![Look4nurns](https://avatars.discourse-cdn.com/v4/letter/l/b487fb/32.png) [@Look4nurns](https://scilab.discourse.group/u/Look4nurns)\
**Post date:** [July 13, 2023, 7:29am UTC](https://scilab.discourse.group/t/creating-and-exporting-surface-from-points/115/10 "2023-07-13T07:29:16Z")

</div>

Hello  
I’d like to have a iges or step surface. STL is bad for me bacause I have to use the file in a cad,  
The .ibl file is a file that I inport in the CAD and create a array of points that I had to use for creating a surface  
tanks

---

<div class="post-metadata">

**Author:** ![mottelet](https://yyz2.discourse-cdn.com/free1/user_avatar/scilab.discourse.group/mottelet/32/13_2.png) [@mottelet](https://scilab.discourse.group/u/mottelet)\
**Post date:** [July 13, 2023, 7:51am UTC](https://scilab.discourse.group/t/creating-and-exporting-surface-from-points/115/11 "2023-07-13T07:51:58Z")

</div>

Sorry, Scilab has no IGES or STEP converter. Maybe NURBS conversion can be done by other software. However, STL conversion of a Scilab Fac3d object is quite easy to do, if you can convert STL to another format afterwards it may be the way to go for your problem.

S.

---

<div class="post-metadata">

**Author:** ![Look4nurns](https://avatars.discourse-cdn.com/v4/letter/l/b487fb/32.png) [@Look4nurns](https://scilab.discourse.group/u/Look4nurns)\
**Post date:** [July 13, 2023, 8:32am UTC](https://scilab.discourse.group/t/creating-and-exporting-surface-from-points/115/12 "2023-07-13T08:32:03Z")

</div>

Thanks  
OK maybe I can try with STL and check for a conversion  
S

---

<div class="post-metadata">

**Author:** ![mottelet](https://yyz2.discourse-cdn.com/free1/user_avatar/scilab.discourse.group/mottelet/32/13_2.png) [@mottelet](https://scilab.discourse.group/u/mottelet)\
**Post date:** [July 13, 2023, 10:15am UTC](https://scilab.discourse.group/t/creating-and-exporting-surface-from-points/115/13 "2023-07-13T10:15:18Z")

</div>

Here is a script to do the conversion to STL:

```auto
// find object
h = findobj("type","Fac3d");
X = [h.data.x;mean(h.data.x,1)]
Y = [h.data.y;mean(h.data.y,1)];
Z = [h.data.z;mean(h.data.z,1)];
// add center vertex and form triangles
X=[X([5 1 2],:) X([5 2 3],:) X([5 3 4],:) X([5 4 1],:)];
Y=[Y([5 1 2],:) Y([5 2 3],:) Y([5 3 4],:) Y([5 4 1],:)];
Z=[Z([5 1 2],:) Z([5 2 3],:) Z([5 3 4],:) Z([5 4 1],:)];
// sides vectors
U=[X(2,:)-X(1,:); Y(2,:)-Y(1,:); Z(2,:)-Z(1,:)];
V=[X(3,:)-X(1,:); Y(3,:)-Y(1,:); Z(3,:)-Z(1,:)];
// normals computation
NX=U(2,:).*V(3,:)-U(3,:).*V(2,:);
NY=U(3,:).*V(1,:)-U(1,:).*V(3,:);
NZ=U(1,:).*V(2,:)-U(2,:).*V(1,:);
// write STL file
n = size(X,2);
fd = mopen('object.stl','wt');
mfprintf(fd,"solid object\n");
for i = 1:n
    mfprintf(fd,"facet normal %f %f %f\n",NX(i),NY(i),NZ(i));
    mfprintf(fd," outer loop\n");
    mfprintf(fd," vertex %f %f %f\n",X(1,i),Y(1,i),Z(1,i));
    mfprintf(fd," vertex %f %f %f\n",X(2,i),Y(2,i),Z(2,i));
    mfprintf(fd," vertex %f %f %f\n",X(3,i),Y(3,i),Z(3,i));
    mfprintf(fd," endloop\n");
    mfprintf(fd,"endfacet\n");
end
mfprintf(fd,"endsolid object");
mclose(fd);

```

resulting geometry looks good in online STL viewers:  
 ![Capture d’écran 2023-07-13 à 12.07.47](https://global.discourse-cdn.com/free1/uploads/utc/original/1X/ce9f2f6673456e9df7ffcaad1560b01d4fa56024.png)

---

<div class="post-metadata">

**Author:** ![Look4nurns](https://avatars.discourse-cdn.com/v4/letter/l/b487fb/32.png) [@Look4nurns](https://scilab.discourse.group/u/Look4nurns)\
**Post date:** [July 13, 2023, 10:24am UTC](https://scilab.discourse.group/t/creating-and-exporting-surface-from-points/115/14 "2023-07-13T10:24:10Z")

</div>

thanks  
I’ll check it

---

<div class="post-metadata">

**Author:** ![Look4nurns](https://avatars.discourse-cdn.com/v4/letter/l/b487fb/32.png) [@Look4nurns](https://scilab.discourse.group/u/Look4nurns)\
**Post date:** [July 13, 2023, 10:32am UTC](https://scilab.discourse.group/t/creating-and-exporting-surface-from-points/115/15 "2023-07-13T10:32:59Z")

</div>

Sorry  
the code is a generic one?  
It isn’t the same you put in my scilab file in order to obtain this stl file.  
I’ve tryed but it doesn’t work

---

<div class="post-metadata">

**Author:** ![Look4nurns](https://avatars.discourse-cdn.com/v4/letter/l/b487fb/32.png) [@Look4nurns](https://scilab.discourse.group/u/Look4nurns)\
**Post date:** [July 13, 2023, 1:21pm UTC](https://scilab.discourse.group/t/creating-and-exporting-surface-from-points/115/16 "2023-07-13T13:21:34Z")

</div>

Ok now it works  
I need something smother!  
do you thinck that scilab could connect to open library for nurbs generator?  
s

---

<div class="post-metadata">

**Author:** ![mottelet](https://yyz2.discourse-cdn.com/free1/user_avatar/scilab.discourse.group/mottelet/32/13_2.png) [@mottelet](https://scilab.discourse.group/u/mottelet)\
**Post date:** [July 13, 2023, 5:24pm UTC](https://scilab.discourse.group/t/creating-and-exporting-surface-from-points/115/17 "2023-07-13T17:24:51Z")

</div>

You can arbitrarily (by changing the two `100` occurences below) refine the original surface given by your 3 matrices `x3,y3,z3` by spline interpolation with `splin2d` and `interp2d` with the following code. Insert it before STL export.

```auto
[N,M]=size(x3);
cx=splin2d(1:N,1:M,x3);
cy=splin2d(1:N,1:M,y3);
cz=splin2d(1:N,1:M,z3);
[I,J]=ndgrid(linspace(1,N,100),linspace(1,M,100));
X3=interp2d(I,J,1:N,1:M,cx);
Y3=interp2d(I,J,1:N,1:M,cy);
Z3=interp2d(I,J,1:N,1:M,cz);

mesh(X3,Y3,Z3)

```

 ![Capture d’écran 2023-07-13 à 19.23.58](https://global.discourse-cdn.com/free1/uploads/utc/original/1X/c3f507deaf39ab4edd90ade3419d32e503fd2979.png)

---

<div class="post-metadata">

**Author:** ![Look4nurns](https://avatars.discourse-cdn.com/v4/letter/l/b487fb/32.png) [@Look4nurns](https://scilab.discourse.group/u/Look4nurns)\
**Post date:** [July 14, 2023, 6:47am UTC](https://scilab.discourse.group/t/creating-and-exporting-surface-from-points/115/18 "2023-07-14T06:47:40Z")

</div>

Thank you very much!

Another thing  
i have another version of the code where I create a series of surfaces with different sweep (see add)  
[sfalsatura.sod](https://scilab.discourse.group/uploads/short-url/sjv9jUTjbhXXgA6V7GPICdBwKJL.sod) (1.5 KB)  
I have tryed do add the STL part at the end (after “// Scrittura file IBL con tutte le catene  
// Superficie Unica Pala”) but I have only the last geometry.  
thanks  
s

---

<div class="post-metadata">

**Author:** ![mottelet](https://yyz2.discourse-cdn.com/free1/user_avatar/scilab.discourse.group/mottelet/32/13_2.png) [@mottelet](https://scilab.discourse.group/u/mottelet)\
**Post date:** [July 14, 2023, 8:13am UTC](https://scilab.discourse.group/t/creating-and-exporting-surface-from-points/115/19 "2023-07-14T08:13:30Z")

</div>

I think you can adapt the code yourself: insert the exporting code in your loop and clear the figure between each surface plot, and also change the STL file name.

S.

---

<div class="post-metadata">

**Author:** ![Look4nurns](https://avatars.discourse-cdn.com/v4/letter/l/b487fb/32.png) [@Look4nurns](https://scilab.discourse.group/u/Look4nurns)\
**Post date:** [July 20, 2023, 2:48pm UTC](https://scilab.discourse.group/t/creating-and-exporting-surface-from-points/115/20 "2023-07-20T14:48:59Z")

</div>

Hi  
I’ve tryed but I’m too low in scilab programming.  
Can you haelp me?

[Next page](https://scilab.discourse.group/t/creating-and-exporting-surface-from-points/115.md?page=2)
