# 3D cube with 1D-Line in the middle

**URL:** <https://community.freefem.org/t/3d-cube-with-1d-line-in-the-middle/4104>\
**Category:** General Discussion\
**Created:** [October 16, 2025, 11:40pm UTC](https://community.freefem.org/t/3d-cube-with-1d-line-in-the-middle/4104 "2025-10-16T23:40:05Z")\
**Posts on this page:** 1\
**Showing post:** 8

<div class="post-metadata">

**Author:** ![fb77](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/fb77/32/3796_2.png) [@fb77](https://community.freefem.org/u/fb77)\
**Post date:** [October 20, 2025, 9:59am UTC](https://community.freefem.org/t/3d-cube-with-1d-line-in-the-middle/4104/8 "2025-10-20T09:59:20Z")

</div>

Sebastian,  
you can also define the curve as a parametric curve instead of using an external file:

```auto
load "msh3"
load "tetgen"

mesh3 Th=cube(2,2,2);// Define the mesh without the curve

real[int] xc(Th.nv),yc(Th.nv),zc(Th.nv);
for (int i=0;i<Th.nv;i++){//save the coordinates of the vertices of the mesh
 xc(i)=Th(i).x;
 yc(i)=Th(i).y;
 zc(i)=Th(i).z;
}

border curv(t=0.,1.){x=t+0.1*cos(2.*pi*t);y=t+0.1*sin(2.*pi*t);z=t;}//define a parametric curve
int nbpts=5;//number of points on the curve
meshL ThL=buildmeshL(curv(nbpts-1));// build the 1d mesh of the curve
//plot(ThL,wait=1);

real[int] ptsx(nbpts);// coordinate x of points on the curve
real[int] ptsy(nbpts);// coordinate y of points on the curve
real[int] ptsz(nbpts);// coordinate z of points on the curve
for (int i=0;i<nbpts;i++){
 ptsx(i)=ThL(i).x;
 ptsy(i)=ThL(i).y;
 ptsz(i)=ThL(i).z;
}
cout << "ptsx " << ptsx << endl << " ptsy " << ptsy << endl << " ptsz " << ptsz << endl;

xc.resize(Th.nv+nbpts);
yc.resize(Th.nv+nbpts);
zc.resize(Th.nv+nbpts);
for (int j=0;j<nbpts;j++){//complete the set of vertices with the points of the curve
 xc(Th.nv+j)=ptsx(j);
 yc(Th.nv+j)=ptsy(j);
 zc(Th.nv+j)=ptsz(j);
}
Th=tetgconvexhull(xc,yc,zc);//rebuild the mesh with this extended set of vertices
plot(Th,wait=1);
//savemesh(Th,"Th.mesh");

int[int] indpts(nbpts);//array giving the indices of the curve points as vertices of the 3d mesh
for (int i=0;i<Th.nv;i++){
 for (int j=0;j<nbpts;j++){
  if ((abs(Th(i).x-ptsx(j))<1.e-8)&&(abs(Th(i).y-ptsy(j))<1.e-8)&&(abs(Th(i).z-ptsz(j))<1.e-8)){
   indpts(j)=Th(i);
  }
 }
}
cout << "indpts " << indpts << endl;

```

---

_[View the full topic](https://community.freefem.org/t/3d-cube-with-1d-line-in-the-middle/4104)._
