sicp-lang/sicp

How does the coordinate mapping work?

Closed this issue · 3 comments

It seems that instead of frame-coord-map, this implementation maps the points in the unit square to the actual output device by manipulating the transformation matrix. I played a little bit, but can't grasp how it's done.

Take this painter as an example:

(define line (vects->painter (list (make-vect 0 0) (make-vect 1 1))))

The transformation matrix right before it draws the line is #(198.0 0.0 0.0 -198.0 0.0 200.0). I verify the mapping by hand using the formula. It correctly maps '(0 0) to '(0 200), and '(1 1) to '(200 0). (I use #(200.0 0.0 0.0 -200.0 0.0 200.0) for easy calculation.)

But when I run the following code:

(define bm (make-bitmap 200 200))
(define dc (new bitmap-dc% [bitmap bm]))
(send dc set-initial-matrix (vector 198.0 0.0 0.0 -198.0 0.0 200.0))
(send dc draw-line 0.0 0.0 1.0 1.0)

It just gives this picture

untitled

What am I missing?

It works. Thank you very much.

Great it worked.