4
votes

In the picture language in SICP I'm having trouble understanding how the transform-painter procedure works:

(define (transform-painter painter origin corner1 corner2)
  (lambda (frame)
    (let ((m (frame-coord-map frame)))
      (let ((new-origin (m origin)))
        (painter
         (make-frame new-origin
                     (sub-vect (m corner1) new-origin)
                     (sub-vect (m corner2) new-origin)))))))

Specifically why the vector subtraction of the edge mappings of the argument frame by the new-origin is necessary. I would have thought the mapping of the new corners, i.e (m corner1) and (m corner2), could serve as the new edges of the transformed frame.

I've done some calculation and I want to know where i'm mixed up. Taking flip-vert as an example,

(define (flip-vert painter)
  (transform-painter painter
                     (make-vect 0.0 1.0)   ; new origin
                     (make-vect 1.0 1.0)   ; new end of edge1
                     (make-vect 0.0 0.0))) ; new end of edge2

let flip-vert take as argument a frame with the following dimensions,

Origin = (0, 0), Edge1 = (4, 0), Edge2 = (0, 4)

Accordingly the mapping formula would become (0,0) + x(4,0) + y(0, 4).

In the case of flip-vert the origin, corner1, and corner2 passed as arguments to transform-painter are (0,1), (1,1) and (0,0) respectively.

So after placing them in the mapping formula, one after the other, we get the results

new-origin = (0,0)+0*(4,0)+1*(0,4) = (0,4)

mapped-corner1 = (0,0)+1*(4,0)+1*(0,4) = (4,4)

mapped-corner2 = (0,0)

Now the transform-painter takes the final two results and subtracts them by the new-origin to build the new frame, resulting in a frame with the following dimensions.

Origin = (0,4), New-corner1 = (4,0), New-corner2 = (0,-4)

Looking at these points on a coordinate plane the results don't seem right, while the original corner results before the subtractions took place, do. What am I doing wrong?

1

1 Answers

1
votes

Please look at the attached pic (sorry for my drawing skills :) ). i have marked as m corner1 the transformed vector that you say it would suffice as the new corner for new frame onto which the painter is going to act ( m corner1 is the m coordinate transformation mapped onto corner1 point).

But observe that this is a vector that just "ends" at the right point. You have to translate the origin too in order to get a correct frame. Observe now that the new origin lies at the point new origin and that the new corner that you seek (the red one) is indeed the vector difference of the previous two.

the blue frame that lies in the unit square is mapped onto the red frame

(the pic shows the blue frame that lies in the unit square being mapped onto the red frame)