# Interpreting a formula for Blender Python

I'm pretty poor at maths but managed to get someone who is decent at it to come up with a linear algebraic formula for the control over the distribution of points along a straight line.

The formula is:

$$f(x) = \left(\frac xL\right)^{\frac 1c}L$$

Would anyone be kind enough and help me translate that into a function I can write within Blender python?

Thanks in advance.

## 2 Answers

With numpy

An ideal candidate for using numpy For example, can define a sequence

>>> x = np.arange(5)
>>> x
array([0, 1, 2, 3, 4])


and run a function quickly over all items, simple example squaring them.

>>> np.power(x, 2)
array([ 0,  1,  4,  9, 16])


Halving and squaring

>>> np.power(x / 2, 2)
array([0.  , 0.25, 1.  , 2.25, 4.  ])


The question equation.

Test script, defines a function of $$x$$ with scalars (assume they're scalars) $$L$$ and $$c$$

import bpy
import numpy as np

def distribute(x, L, c):
return L * np.power(x / L, 1 / c)

# test run

x = np.arange(20)
for d in distribute(x, 10, 2):
bpy.ops.object.empty_add(location=(d, 0, 0))


Empties placed as result of test run.

Related.

Create curve from Numpy Array using Python

• What an excellently described answer. Thanks for this. Numpy really is a great extension to the core functionality. Apr 12, 2021 at 19:14

The python expression is:

y = (x / L) ** ( 1 / c) * L

• Although I'm going with the answer above, this is still really useful to know what the literal translation looks like. So thanks for your input. Apr 12, 2021 at 19:16