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:

http://farm9.staticflickr.com/8358/8275789109_27d3ca12ac_o.jpg

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:

http://farm9.staticflickr.com/8065/8275789119_866d6b39d0_o.jpg

Our original vectors were:

http://farm9.staticflickr.com/8498/8275789131_c1f37c7384_o.jpg

Applying the affine transformation to these three vectors, we obtain:

http://farm9.staticflickr.com/8343/8275789895_cf338f8707_o.jpg

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)))

http://farm9.staticflickr.com/8490/8265666635_81050ca360_o.jpg http://farm9.staticflickr.com/8204/8266735592_e4bd23a7f7_o.jpg

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:

http://farm9.staticflickr.com/8494/8275789913_cd937b681f_o.jpg

http://farm9.staticflickr.com/8059/8275789931_71a54f46bb_o.jpg

http://farm9.staticflickr.com/8206/8275789945_07588a84e0_o.jpg

Applying this affine transformation to our original set of vectors, we obtain:

http://farm9.staticflickr.com/8500/8276851232_846c85ac60_o.jpg

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)))

http://farm9.staticflickr.com/8490/8265666635_81050ca360_o.jpg http://farm9.staticflickr.com/8214/8266735610_f495195973_o.jpg

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:

http://farm9.staticflickr.com/8494/8275789913_cd937b681f_o.jpg

http://farm9.staticflickr.com/8208/8275790649_ff25eea5d8_o.jpg

http://farm9.staticflickr.com/8501/8275790665_77cecaceed_o.jpg

Applying this affine transformation to our original set of vectors, we obtain:

http://farm9.staticflickr.com/8496/8276852938_e015df06c4_o.jpg

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)))

http://farm9.staticflickr.com/8490/8265666635_81050ca360_o.jpg http://farm9.staticflickr.com/8356/8265666683_69517cf1e5_o.jpg