### Barnsley Fern too thin

• 3 Replies
• 152 Views

0 Members and 1 Guest are viewing this topic.

#### matigekunstintelligentie

• Fractal Freshman
• Posts: 4

#### Barnsley Fern too thin

« on: September 06, 2020, 10:15:22 PM »
I'm trying to write code that converts affine transformations from matrix form to angles and lengths to render fractals in chaotica. The resulting Fern however is too thin. It looks like the Barnsley Fern but more condensed and I'm wondering what I'm doing wrong. Initially the fern was upside down when using the original translation vector, but this was resolved after multiplying this vector with -1. I also offset the y angle by 90 degrees as this what the default vector in Chaotica has as y angle value.

The code is as follows:

Code: [Select]
import numpy as np# Barnsley Fern affine transformations# Format a b c d e f p -> [a, b// c, d][x//y]+[e//f] where p is the probability weightfunction_set = [[0.0, 0.0, 0.0, 0.16, 0.0, 0.0, 0.01],                [0.85, 0.04, -0.04, 0.85, 0.0, 1.6, 0.85],                [0.2, -0.26, 0.23, 0.22, 0.0, 1.6, 0.07],                [-0.15, 0.28, 0.26, 0.24, 0.0, 0.44, 0.07]]# Calculates the angle between two vectors in degreesdef angle(vector_1, vector_2):    vector_1 = np.array(vector_1)    vector_2 = np.array(vector_2)    # Calculate signed angle between vectors    # Using answer https://stackoverflow.com/questions/2150050/finding-signed-angle-between-vectors by Derek Ledbetter    angle = np.rad2deg(np.arctan2( vector_1[0]*vector_2[1] - vector_1[1]*vector_2[0], vector_1[0]*vector_2[0] + vector_1[1]*vector_2[1] ))    return angledef affine_transformation(f, c0, c1):    x = c0 * f[0] + c1 * f[1]    y = c0 * f[2] + c1 * f[3]    return [x, y]for i in range(len(function_set)):# calculate length and angle for the unit square x vector    x = affine_transformation(function_set[i], 1, 0)    length_x = np.linalg.norm(x)    angle_x = angle(x, [1,0]) + 0    translation_x = -function_set[i][4]# calculate length and angle for the unit square y vector    y = affine_transformation(function_set[i], 0, 1)    length_y = np.linalg.norm(y)    angle_y = angle(y, [0,1])    angle_y = angle_y + 90    translation_y = -function_set[i][5]    print("Length x: {}, angle x: {}, translation x: {}".format(length_y, angle_y, translation_y))    print("Length y: {}, angle y: {}, translation y: {}".format(length_x, angle_x, translation_x))
Does anyone know why this happens?

• Posts: 239

#### Re: Barnsley Fern too thin

« Reply #1 on: September 07, 2020, 07:46:48 AM »
I'm assuming it looks too thin when compared to the results on Wikipedia and some images on Google Images... I tried with the original values and got an image similar to yours, and so I looked at the code on Wikipedia to see why theirs is different, and I believe they're just mapping the virtual space differently than us.
You and I are declaring that one unit square of virtual space should be drawn as a properly proportioned square on our screens.
I notice on Wikipedia's Processing example (which it also provides a screenshot of) it's mapping X from -2.182 to 2.6558 onto a 600p wide canvas, and then mapping y from 0 to 9.9983 to 600p high, if I understand that code correctly.

So it looks like it would be significantly stretched horizontally to fill the canvas with the shape in that code. It's not you, it's Wikipedia.

• Posts: 239

#### Re: Barnsley Fern too thin

« Reply #2 on: September 07, 2020, 07:58:04 AM »
Here's my quick attempt as a demonstration, btw...

My program only has three transform options set up at the moment, so I omitted the stem, since I didn't have the energy to code up the fourth (or to do what I should have done from the beginning and make the number of transforms expandable... one day)

#### matigekunstintelligentie

• Fractal Freshman
• Posts: 4

#### Re: Barnsley Fern too thin

« Reply #3 on: September 11, 2020, 08:13:48 PM »
You are absolutely correct! Didn't notice the mapping on Wikipedia. Thank you!

I fixed my code. For future reference: the affine translations in Chaotica should be multiplied by -1 and the y angle should be rotated 90 degrees to get the correct mapping from affine transformations to Chaotica

### Similar Topics

###### Thin theme

Started by Lois on Fractal Image Gallery

0 Replies
139 Views
December 19, 2017, 02:47:35 PM
by Lois
###### Barnsley Techno J Documentation?

Started by DoctorT on Noob's Corner

1 Replies
215 Views
March 26, 2019, 12:23:29 AM
by 3DickUlus
###### (Ultra Fractal) Barnsley formula

Started by Anon on Image Threads

21 Replies
1463 Views
March 05, 2018, 12:39:57 AM
by Anon