Loading [MathJax]/jax/output/CommonHTML/fonts/TeX/fontdata.js
Building a Koch Snowflake
- Our goal for the day
- Reference.
- This is a fractal example.
- To build this snowflake
- Each line segment is replaced by:
- A line segment from the start to 1/3 of the way in.
- A line segment from 1/3 to the equivalent at a 60∘
- A line segment from the last to a point 2/3 of the way along the original line.
- A line segment from 2/3 of the way to the final point.
- There are a few techniques and a little math involved in displaying this.
- Points or vectors?
- I tend to go back and forth in my mind.
- When I need linear items, they are vectors
- Other times they are points.
- I'm not sure this totally make sense but let's look at a few functions.
- In
Distance
this is the classic distance formula, and the input is definitely points.
- In OnLine I am thinking in a vector mode.
- This generates a point a distance along the line.
- IE 1/3 of the distance, 1/2 of the distance and 2/3 of the distance.
- It just computes a vector the length of the line segment.
- And then travels a distance along that vector.
- In
FindPerp
I think I am thinking more in a vector mode.
- This finds the perpendicular line to a given line at a point.
- Remember the slope of a perpendicular is −1m
- But I don't know how far along that line to go at first.
- So I create a unit vector perpendicular to the given line, at the second end point.
- To do this
- Calculate one of the deltas as a negative.
- Make the deltas a unit vector.
- Add the deltas to the second end point.
- Finally I move along the new line the required distance to a new point.
- The the starting points are based off of the canvas width and height.
- The computing of the curve is iterative, but it could be recursive.