Converting simplified Gielis equation (polar) to parametric equation

58 Views Asked by At

I found the simplified Gielis equation, that discribes the shape of a leaf. The equation states:

$ r = \frac{l} {(|cos \frac{θ}{4}| + |sin\frac{θ}{4}|)^\frac{1}{n}}$

To get to the Cartesian coordinates you add:

$ x = cos(θ) \times r$

$ y = sin(θ) \times r$

On the web I can only find the polar, but not the parametric version of the equation. For my project I would like the parametric version, so I can add $x$ to the equation, to get $y$. So that would be:

$y = f(x)$

I have already tried Wolfram Alpha and Sympy, but it couln't manage to solve the equation.

Can someone please help me with the step by step explanation?

1

There are 1 best solutions below

1
On

Ok, I used the python package Scipy Interp1d to do an interpolation of the equation. From the interpolation you can enter the x value, and Scipy will give the y value.

No rearangement of the formula needed anymore :)

EDIT:

from scipy import interpolate
import pandas as pd
import numpy as np

def Gielis():
        row_index_df_b = 0
        # theta must be 360 degrees to get a full leaf
        for theta in range(0, int(360+1), 1):
            l = 4
            n = 3
            r = l / (np.abs(np.cos(np.radians(theta) / 4)) + np.abs(np.sin(np.radians(theta) / 4))) ** (1 / n)
            x = np.cos(np.radians(theta)) * r
            y = np.sin(np.radians(theta)) * r
            
            #create df
            df_b.loc[row_index_df_b, 'x'] = x
            df_b.loc[row_index_df_b, 'y'] = y
            df_b.loc[row_index_df_b, 't'] = theta
            row_index_df_b = row_index_df_b + 1

         # edit kind to linear, quadratic or cubic
         interpolation = interpolate.interp1d(df_b['x'].to_numpy().astype(float), df_b['y'].to_numpy().astype(float), kind='cubic')

         interpolated_y_value = interpolation(your_x_value)

Gielis()