# SICP Solutions

### Section - 2.2 - Hierarchical Data and the Closure Property

#### Exercise 2.49

Note that in all the exercises, we can use coordinates of a unit square i.e. $0 \le x \le 1$ and $0 \le y \le 1$. Now the method frame-coord-map will maps our coordinates to the given frame.

(a)

As shown in the book, if we take $x = 0$ and $y = 0$, in the unit square it will be transformed to origin of the designated frame. Similarly it follows for any value of $x$ and $y$.

Thus, to draw the outline of the frame, we just need to draw outline of unit square. The method frame-coord-map will take care to transform our points to the points in the designated frame.

Output/Test:

Ideally (draw-frame (make-frame (make-vect 0 0) (make-vect 5 5) (make-vect 10 10))) should also draw the outline of the passed frame. It apparently does not work. It seems the draw-line procedure is works correctly only while using paint.

The problem with paint is it draws only in a unit square frame. Thus to actually verify that points are correctly transformed and can outline any frame is possible only if procedure segments-painter are implemented without using draw-line. Thus instead of draw-line, use some new procedure which invokes Racket Graphics package to draw line.

Currently because of time constraint, I am using segments-painter currently available with sicp package of Dr Racket.

(b)

Output/Test:

(c)

(d)

It is too time consuming and similar to earlier exercises. As it is used in next exercise, I am using a solution from wiki: