# Further modelling techniques with python

## Part 2: Advanced Techniques in Erythrocyte Modeling

### Recap of Part 1

In Part 1 of this series, we delved into the fascinating world of erythrocyte modeling. We explored the mathematical representation of erythrocytes using signed distance functions (SDFs) and highlighted the elegance of the Skalak model. We discussed how to embrace the rotational symmetry of erythrocytes, create a 2D SDF, and revolve it to obtain a 3D model.

### Introducing Other Techniques

Now, in Part 2, we'll build upon the foundation we've established and explore other techniques for erythrocyte modeling. Let's start by introducing some Python code with small adjustments to our previous method:

```
from sdf import *
diameter = 7.6
def ery(d=diameter, steps=100):
c0 = 0.01384083
c1 = 0.2842917
c2 = 0.01306932
x = np.linspace(-1, 1, steps)
z2 = 0.86**2 * (1 - x**2) * (c0 + c1*x**2 + c2*x**4)
z = np.sqrt(z2)
points = np.concatenate((np.stack((x,z), axis=-1), np.stack((x,-z), axis=-1)[-2:0:-1])) * d/2
return polygon(points)
f = ery().revolve()
```

## Modeling Non-Uniform Erythrocytes

While the Skalak model provides an excellent representation of typical erythrocytes, real-life erythrocytes often exhibit a degree of non-uniformity in their shape. This variability can arise from various factors, including mechanical stress, disease conditions, or environmental influences. In Part 2, we'll explore how to model these non-uniform erythrocytes.

### Introducing the `bend_linear`

Function

To simulate the deformations and non-uniformities that erythrocytes may experience, we'll use the `bend_linear`

function. This function allows us to introduce bends and deformations to our erythrocyte model. Here's how it works:

```
offset = 0.2 # This reduces artefacts at the edges of our model
f = f.bend_linear(-X * diameter/2 - offset, X * diameter/2 + offset, 2*Z, lambda x: 2 * np.sqrt(x - x**2) - 0.5)
```

The `bend_linear`

function takes several arguments:

- The first two parameters define the interval over which the deformation occurs.
- The third parameter determines the direction where the bending takes place.
- The last parameter, a lambda function, defines how the deformation is applied, mapping values from the normalized interval [0, 1] to a scalar, which will be multiplied with the third parameter.

Here is the result:

Additionally, to account for non-uniformities in the y-axis, we can employ the bend_linear function with a linear function along the y-axis to add some asymmetry to the model:

```
f = f.bend_linear(-Y * diameter/2 - offset, Y * diameter/2 + offset, Z, lambda x: x)
```

Now we should see the following:

### Exporting the Model

Exporting the model is straightforward. You can use a simple line of code to save your model in STL format:

```
f.save('ery_x_y.stl')
```

We've covered some techniques for modeling non-uniform erythrocytes and demonstrated how to export our models for various applications. I encourage you to try out these modelling approaches for example by modeling special forms of erythrocytes, such as spherocytes. Happy modeling! ðŸ©¸