# Access normal vector

**URL:** https://community.freefem.org/t/access-normal-vector/274
**Category:** General Discussion
**Created:** [February 26, 2020, 12:13pm UTC](https://community.freefem.org/t/access-normal-vector/274 "2020-02-26T12:13:43Z")
**Posts on this page:** 11
**Page:** 1

<div class="post-metadata">

### Author: ![BeniaminBogosel](https://avatars.discourse-cdn.com/v4/letter/b/3ec8ea/32.png) [@BeniaminBogosel](https://community.freefem.org/u/BeniaminBogosel)
#### Post date: [February 26, 2020, 12:13pm UTC](https://community.freefem.org/t/access-normal-vector/274/1 "2020-02-26T12:13:43Z")

</div>

I would like to try and write some code for approximating the curvature of the boundary of the mesh. The current solution proposed in the function “curvature” does not work too well and I would like to try other variants.

The normals computed in FreeFEM are normals to the edges of the boundary or normals approximated at the vertices on the boundary?

---

<div class="post-metadata">

### Author: ![simon.garnotel](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/simon.garnotel/32/11_2.png) [@simon.garnotel](https://community.freefem.org/u/simon.garnotel)
#### Post date: [February 26, 2020, 7:36pm UTC](https://community.freefem.org/t/access-normal-vector/274/2 "2020-02-26T19:36:45Z")

</div>

Normals are computed on integration points, you can save it in a vector using this trick:

```auto
mesh Th = square(10, 10);
fespace Uh(Th, P1);

int i = 0, j = 0;
real[int] nx(Uh.ndof), ny(Uh.ndof);
real a = int1d(Th)((nx[i++] = N.x) + (ny[j++] = N.y));
cout << nx << endl;
cout << ny << endl;

```

---

<div class="post-metadata">

### Author: ![AFourmont](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/afourmont/32/56_2.png) [@AFourmont](https://community.freefem.org/u/AFourmont)
#### Post date: [February 27, 2020, 11:29am UTC](https://community.freefem.org/t/access-normal-vector/274/3 "2020-02-27T11:29:00Z")

</div>

I suppose that your question is about surface mesh

The “curvature”function is defined for a 2D mesh. An equivalent for surface 3D could be developed as soon as possible

For a meshS, there are 2 types of normals computed in FreeFEM  
-\> N is the exterior normals (flux)  
-\> Nt is normal the surface element  
normals at vertices doesn’t exist for the moment, elements are flat

Axel

---

<div class="post-metadata">

### Author: ![BeniaminBogosel](https://avatars.discourse-cdn.com/v4/letter/b/3ec8ea/32.png) [@BeniaminBogosel](https://community.freefem.org/u/BeniaminBogosel)
#### Post date: [February 27, 2020, 12:40pm UTC](https://community.freefem.org/t/access-normal-vector/274/4 "2020-02-27T12:40:54Z")

</div>

Thank you for this information. @Simon: nice trick for saving the normal information!

In fact, my question is about a 2D mesh. The curvature function works well when the mesh comes from “buildmesh” with a nice parametrization, but I have the impression that it is not too stable. For example, when computing the curvature of a slightly perturbed disk using “curvature” the result oscillates too much.

---

<div class="post-metadata">

### Author: ![zou1234](https://avatars.discourse-cdn.com/v4/letter/z/e274bd/32.png) [@zou1234](https://community.freefem.org/u/zou1234)
#### Post date: [March 15, 2020, 12:30pm UTC](https://community.freefem.org/t/access-normal-vector/274/5 "2020-03-15T12:30:05Z")

</div>

Dear Beniamin Bogosel,  
Thank you for your question! I am also caught in the problem that the function ''curcature‘’ does not work. There is a compile error about the code ~load “curvature”~, I can not load it, have you ever solved this trouble? Many thanks!

---

<div class="post-metadata">

### Author: ![BeniaminBogosel](https://avatars.discourse-cdn.com/v4/letter/b/3ec8ea/32.png) [@BeniaminBogosel](https://community.freefem.org/u/BeniaminBogosel)
#### Post date: [May 13, 2020, 10:09pm UTC](https://community.freefem.org/t/access-normal-vector/274/6 "2020-05-13T22:09:52Z")

</div>

Sorry for replying this late. You should use `load "Curvature"` with upper case C. Then using `Kappa = curvature(Th,label);` should work, where `Th` is a mesh variable and `label` is the boundary Label. Also `Kappa` must be a `P1` finite element function on the mesh `Th`.

---

<div class="post-metadata">

### Author: ![mariancantal](https://avatars.discourse-cdn.com/v4/letter/m/a9adbd/32.png) [@mariancantal](https://community.freefem.org/u/mariancantal)
#### Post date: [February 1, 2022, 6:24am UTC](https://community.freefem.org/t/access-normal-vector/274/7 "2022-02-01T06:24:24Z")

</div>

Hi! Can we use the curvature command to a level set function?

---

<div class="post-metadata">

### Author: ![frederichecht](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/frederichecht/32/15_2.png) [@frederichecht](https://community.freefem.org/u/frederichecht)
#### Post date: [February 1, 2022, 10:49am UTC](https://community.freefem.org/t/access-normal-vector/274/8 "2022-02-01T10:49:17Z")

</div>

Use the plugin “distance”

eee example: forme the source :  
[distance2](https://github.com/FreeFem/FreeFem-sources/blob/master/examples/plugin/distance2.edp)  
[distance](https://github.com/FreeFem/FreeFem-sources/blob/master/examples/plugin/distance.edp)

---

<div class="post-metadata">

### Author: ![mariancantal](https://avatars.discourse-cdn.com/v4/letter/m/a9adbd/32.png) [@mariancantal](https://community.freefem.org/u/mariancantal)
#### Post date: [February 1, 2022, 11:07am UTC](https://community.freefem.org/t/access-normal-vector/274/9 "2022-02-01T11:07:04Z")

</div>

Hi Sir!. I am confused about how I am going to incorporate the command distance. If I have kappa as the curvature of my level set function, then  
kappa = curvature(Th, levelset=phi). But this is not workable since the command curvature works on the boundary of the mesh. Please correct me if I am wrong. Thank you!

---

<div class="post-metadata">

### Author: ![frederichecht](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/frederichecht/32/15_2.png) [@frederichecht](https://community.freefem.org/u/frederichecht)
#### Post date: [February 1, 2022, 2:28pm UTC](https://community.freefem.org/t/access-normal-vector/274/10 "2022-02-01T14:28:17Z")

</div>

Yes , curvature function compute the curvature of a mesh boundary.  
but if \psi is a distance function of the levelest \phi=0,  
then \nabla(\psi) is an approximation the normal to the level set and  
 \nabla\nabla(\psi).\tau.\tau is a approximation de the curvature (where \tau is the tangent to the level set, but not well defined, because \psi is affine on each triangle.

---

<div class="post-metadata">

### Author: ![luisrocag](https://avatars.discourse-cdn.com/v4/letter/l/7993a0/32.png) [@luisrocag](https://community.freefem.org/u/luisrocag)
#### Post date: [February 9, 2022, 12:53pm UTC](https://community.freefem.org/t/access-normal-vector/274/11 "2022-02-09T12:53:16Z")

</div>

I capture the level set with isoline function and parameter close=0, after is transform in boundary with border function, finally build a mesh with buildmesh.
