Fractals - PowerPoint PPT Presentation

1 / 21
About This Presentation
Title:

Fractals

Description:

given two lines and the circle center, approximate the chord ... compute the angle ACM where M is the mid-point of AB (define (get-alpha a b c) ... – PowerPoint PPT presentation

Number of Views:92
Avg rating:3.0/5.0
Slides: 22
Provided by: BillL161
Category:
Tags: ab | by | circle | color | fractals | goofy | in | mandelbrot | nature | number | set

less

Transcript and Presenter's Notes

Title: Fractals


1
Fractals
2
Outline
  • Prerequisites
  • Recursion
  • Simple pictures
  • Objectives
  • Drawing Fractal images
  • Examples
  • Mandelbrot set
  • Koch fractal
  • Approximating circles
  • Reference
  • HTDP Section 27.1

3
Background
  • Informally, fractals are endlessly repeating
    geometric figures.
  • Formal Definition Fractal a geometrical figure
    consisting of an identical motif that repeats
    itself on an ever decreasing scale.
  • Fractals come very close to capturing the
    richness and form found in nature.
  • Fractals possess structural self-similarity on
    multiple scales, i.e. a piece of a fractal will
    often look like the whole

4
Well known example Mandelbrot
5
Goofy Question
  • What is the distance around the shore of Lake
    Lanier?
  • Normal Answer about 1,000 miles
  • Mathematical Answer it depends on the thickness
    of the line you draw
  • The 1,000 mile answer assumes a line thickness of
    about 10 ft.
  • Who knows what the answer is with a 1/100 inch
    line.
  • What about a line thickness in the molecular
    range?

6
Koch Fractal
  • Simple to draw
  • Replace any line with 4 lines as follows
  • Repeat with the new lines
  • Stop when the line length is smaller than a
    specified limit.

7
Koch Fractal Result
8
Approximating Circles
  • Drawing circles efficiently is not simple
  • Relative pixel size changes the number of lines
    necessary to draw an effective circle
  • Consider the difference between these circles
  • Pixel relatively small - Pixel
    relatively large

9
Calculations
  • All circles drawn on a X-Y grid are
    approximations
  • Each line drawn is an expensive computation
  • We need an algorithm that draws the best circle
    for a given radius relative to the pixel size.

1. Start with a chord from one pixel outside the
circle
4. Continue until the mid-point distance is
closer than a pixel
10
fractal
11
Questions?
12
Code Used 1
  • (define WIDTH 400)
  • (define HEIGHT 400)
  • (define PI 3.14159265)
  • (define center (make-posn (/ WIDTH 2) (/ HEIGHT
    2)))
  • (define DEBUG false)
  • circle posn number color -gt picture
  • start with the center, radius and color and
    draw an
  • approximation to a circle
  • (define (circle center radius color)
  • (let ((pa (offset center (make-posn (- (
    radius 1)) 0)))
  • (pb (offset center (make-posn ( radius
    1) 0))))
  • (and (chord pa pb center radius color)
  • (chord pb pa center radius color))))

13
Code Used 2
  • chord posn posn posn color -gt picture
  • given two lines and the circle center,
    approximate the chord
  • (define (chord pa pb center radius color)
  • (begin (if DEBUG
  • (begin (display "from ")
  • (show-posn pa)
  • (display " to ")
  • (show-posn pb)
  • (display " center ")
  • (show-posn center)))
  • (if (close-enough? pa pb center radius)
  • (draw-solid-line pa pb color)
  • (let ((pc (new-location pa pb center
    radius)))
  • (and (chord pa pc center radius
    color)
  • (chord pc pb center radius
    color))))))

14
Code Used 3
  • new-location posn posn posn -gt posn
  • compute the point on the bisector of the line
    AB that is
  • (radius 1) from the center.
  • (define (new-location a b center radius)
  • (let ((alpha (get-alpha a b center))
  • (beta (get-beta a c)))
  • (get-point center ( radius 1) ( alpha
    beta))))
  • get-alpha posn posn posn -gt number
  • compute the angle ACM where M is the mid-point
    of AB
  • (define (get-alpha a b c)
  • (let ((m (mid-pt a b)))
  • (atan (distance a m)
  • (distance m c))))

15
Code Used 4
  • get-beta posn posn -gt number
  • compute the angle ACX where X is the pt (Ax
    Cy)
  • (define (get-beta a c)
  • (atan (- (posn-y c) (posn-y a))
  • (- (posn-x c) (posn-x a))))
  • get-point posn number number -gt posn
  • calculate the point located from c a distance
    r at angle a
  • (define (get-point c r a)
  • (make-posn (- (posn-x c)
  • ( r (cos a)))
  • (- (posn-y c)
  • ( r (sin a)))))

16
Code Used 5
  • close-enough? posn posn posn number -gt boolean
  • is the mid-point of the chord from pa to pb
    for the circle
  • centered at c with radius r at or beyond
    (radius - 1) from
  • the center?
  • (define (close-enough? pa pb c r)
  • (begin
  • (if DEBUG
  • (begin
  • (display "Check ")
  • (show-posn (mid-pt pa pb))
  • (show-posn c)
  • (display (distance (mid-pt pa pb) c))
  • (newline)))
  • (gt (distance (mid-pt pa pb) c)
  • (- r 1))))

17
Code Used 6
  • mid-pt posn posn -gt posn
  • (define (mid-pt a b)
  • (make-posn (/ ( (posn-x a) (posn-x b)) 2)
  • (/ ( (posn-y a) (posn-y b)) 2)))
  • distance posn posn -gt number
  • (define (distance a b)
  • (sqrt ( (dsq posn-x a b)
  • (dsq posn-y a b))))
  • dsq (posn -gt number) posn posn -gt number
  • (define (dsq f a b)
  • (square (- (f a) (f b))))

18
Code Used 7
  • show-posn posn -gt display
  • diagnostic display of a posn
  • (define (show-posn p)
  • (begin (display "")
  • (display (posn-x p))
  • (display "' ")
  • (display (posn-y p))
  • (display "")
  • (newline)))
  • offset posn posn -gt posn
  • add the coordinates of the parameters to make
    a new position
  • (define (offset a b)
  • (make-posn ( (posn-x a)
  • (posn-x b))
  • ( (posn-y a)
  • (posn-y b))))
  • (start WIDTH HEIGHT)
  • (circle center radius 'red)

19
Final Thought
  • Writing a novel is a lot like drawing a fractal
  • Start with a plot outline
  • Divide the plot into chapters
  • Divide each chapter into sections
  • Divide each section into paragraphs
  • stop dividing when you have a single idea to
    express
  • Flesh out that idea in words
  • The fractal detail adds real-world character to
    the bare story line

20
Summary
  • You should now know
  • Drawing Fractal images
  • Examples
  • Mandelbrot set
  • Koch fractal
  • Approximating circles

21
(No Transcript)
Write a Comment
User Comments (0)
About PowerShow.com