How do I scale and translate my Pentagons properly?
20:44 08 Nov 2025

I am trying to finish a program that will take the world coordinates of polygons, in this case pentagons, and scale and translate them from a world size of 1280x720 so they are drawn based on the center of a 512x288 screen.

I have a function for turning world coordinates into screen coordinates

(define (world-to-screen x-coords y-coords)
  (let*
    ([worldWidth 1280]; define our total world width that we want to work with
     [worldHeight 720]; define world height
     [xScale (/ IMG-Width worldWidth)]; define the scale by wich we will scale polygons
     [yScale (/ IMG-Height worldHeight)]
     [xTrans (/ IMG-Width 2)]; define the amount we will translate the polygons by on the x
     [yTrans (/ IMG-Height 2)]); define the amount we will translate the polygons by on the y

     (vector (+ (* x-coords xScale) xTrans)
                 (+ (* y-coords yScale) yTrans))); return a vector with the new x and y coordinates
)

(world-to-screen 0 0) outputs -> #(256 144)

I have a function for returning the polygon to the world space,

(define (screen-to-world x-coords y-coords); this section will return the polygons to world space so that 
    (let*                                  ; the world to screen conversion would not seem to affect the polygon’s
                                           ;position in world space
    ([worldWidth 1280] ;define world space
     [worldHeight 720] 
     [xScale (/ IMG-Width worldWidth)] ; calculate scale for our polygons 
     [yScale (/ IMG-Height worldHeight)]
     [xTrans (/ IMG-Width 2)]; calculate the translation amount
     [yTrans (/ IMG-Height 2)])

     (vector (/ (- x-coords xTrans) xScale)
             (/ (- y-coords yTrans) yScale))); revert polygons
)

(screen-to-world 256 144) outputs -> #(0,0)

And I combine them into my final function that takes a polygon to move

(define (drawtoscreen Polygon)
  (let*-values
    (
      [(vertex-vector is-closed) (send Polygon get-datum)] ;get the list of verticies and the flag 
    )
      (for ([subpath vertex-vector]);get past the outer parenthsies
          (for ([vertex-pair subpath]); gather the x and y coordinated of the first vertex
            (define x (vector-ref vertex-pair 0))
            (define y (vector-ref vertex-pair 1))

            (vector-set! vertex-pair 0 (vector-ref (world-to-screen x y) 0));set the coordinates of the x and y to thier translated and 
                                                                            ;scaled coordinates
            (vector-set! vertex-pair 1 (vector-ref (world-to-screen x y) 1))
          )
      )

      ;draw translated and scaled polygon
      (send drawing-context draw-path Polygon)

      ;convert the polygon back to world coordinates
      (for ([subpath vertex-vector]);turn back into original coordinates
        (for ([vertex-pair subpath])
        (define x (vector-ref vertex-pair 0))
        (define y (vector-ref vertex-pair 1))
        (vector-set! vertex-pair 0 (vector-ref (screen-to-world x y) 0))
        (vector-set! vertex-pair 1 (vector-ref (screen-to-world x y) 1))
        )
      )
  )
)

I draw my pentagons with the code below

;make pentagon function to edit numbers automatically
(define (make-regular-pentagon cx cy radius [rotation 0])
  (define p (new dc-path%))
  ;
  (define radians (* rotation (/ pi 180)))
  (for ([i (in-range 5)])

    (define angle (+ radians (/ pi -2) (* i (/ (* 2 pi) 5))))

    (define x (+ cx (* radius (cos angle))))
    (define y (+ cy (* radius (sin angle))))
    (if (= i 0); if we are not on the first interation (placeing the brush at the top, then we draw a line to the next vertex)
        (send p move-to x y)
        (send p line-to x y)))
  (send p close)
  p)

;attempt to draw 3 pentagons
(define myPentagon (make-regular-pentagon 0 0 50))

(send drawing-context set-pen "red" 1 'solid)
(send drawing-context set-brush pink 'solid)
(drawtoscreen myPentagon)

(send drawing-context translate 100 70)
(drawtoscreen myPentagon)

(send drawing-context translate 100 70)
(send drawing-context scale .5 .5)
(drawtoscreen myPentagon)

My output

Ideally, the pentagon all the way in the top left (0,0) in world coordinates should be in the center of the window that pops up. I am not sure what is causing the polygons to stay stagnant.

Any help would be appreciated

colors drawing racket scale trigonometry