Affine Transformations, Part I - psholtz/MIT-SICP GitHub Wiki
Define the transformation "flip-horiz" which flips painters horizontally, and transformations that rotate painters counterclockwise by 180 degrees and 270 degrees.
Solution
It's worth noting that each of these transformation can be defined by an affine transformation, and working out what the corresponding linear operator is. In these examples, an affine transformation will be defined by the equation:
where A is an orthogonal operator, and b is a relative displacement.
flip-horiz
flip-horiz is implemented by reflecting through the y-axis, and then displacing by one unit in the positive x-direction (or, in other words, adding the vector (1,0) to the reflection). We can express this mathematically as:
Our original vectors were:
Applying the affine transformation to these three vectors, we obtain:
which, indeed, are the values we assigned in the Scheme procedure.
(define (flip-horiz painter)
(transform-painter painter
(make-vect 1.0 0.0)
(make-vect 0.0 0.0)
(make-vect 1.0 1.0)))
rotate180
rotate180 is obtained by rotating 180 degrees about the z-axis, and then translating one unit in the x-direction (i.e., the vector (1,0)) and translating one unit in the y-direction (i.e., the vector (1,0)), or in the other words, translating through the vector (1,1). We can express this mathematically as:
Applying this affine transformation to our original set of vectors, we obtain:
which are the values we programmed in the Scheme procedure.
(define (rotate180 painter)
(transform-painter painter
(make-vect 1.0 1.0)
(make-vect 0.0 1.0)
(make-vect 1.0 0.0)))
rotate270
rotate270 is obtained by rotating 270 degrees abut the z-axis, and then translating one unit in the y-direction (i.e., the vector (0,1)). We can express this mathematically as:
Applying this affine transformation to our original set of vectors, we obtain:
which are the values we programmed in the Scheme procedure.
(define (rotate270 painter)
(transform-painter painter
(make-vect 0.0 1.0)
(make-vect 0.0 0.0)
(make-vect 1.0 1.0)))