(x, y) back to the origin, by subtracting the coordinates of the pivot point, (x - a, y - b). Firstly we translate the point to be rotated, i.e. To perform rotation around a point different from the origin O(0,0), let's say point A(a, b) (pivot point). Where (x', y') are the coordinates of the point after rotation and angle theta, the angle of rotation (needs to be in radians, i.e. The origin, O(0, 0) is at the upper left corner of the screen.Ī clockwise rotation around the origin of a point with coordinates (x, y) is given by the following equations: the x coordinate increases from left to right and the y coordinate increases from top to bottom. In PostScript if you want a relative moveto you use rmoveto.The coordinate system on the screen is left-handed, i.e. PostScript's 'moveto' is an absolute moveto, not relative. %matrix currentmatrix 4 2 getinterval aload popĨ 0 0 x % execute 8-level-deep expansion of /O in /V % construct arrays, but to save and reset % from the expansion of /O are not used to % The brackets in the procedure resulting " dup 4 matrix currentmatrix 4 2 getinterval" (else (display x) (display " ") (apply send xs)))) Send is a common utility, turtle-init defines the turtle library in PostScript, the rest of the Scheme turtle library follows, then the sample program that draws two squares. The final version of my Scheme code is shown below. I decided not to worry about returning the current position and orientation to Scheme that's too much work for my current purpose, though it may be useful sometime in the future. I'm afraid that each time I say currentpoint translate I interfere with what you are doing in your setpos command. There are two squares, and the second square is tilted at 45 degrees, but both begin at the center of the page. Neither of the setpos commands is honored. Orientation - get current absolute orientationĪn example that draws two squares is shown below the square command writes four lines of length 50, each followed by a 90 degree right turn: initīut that doesn't work. Pendown - % set global variable is_penup to falseįorward n - if is_penup then 0 n rmoveto currentpoint translateīackward n - if is_penup then 0 n neg rmoveto currentpoint translateĮlse 0 n neg rlineto currentpoint translate Penup - % set global variable is_penup to true My library includes the turtle commands shown below with their PostScript equivalents rotateto and setpos are the definitions you gave previously, is_penup is a global variable initially set to true, and I haven't yet considered pos and orientation, which report the current absolute x y position and orientation of the turtle: init - %! Thanks luser droog, but something is still wrong. I'm trying to figure out how to implement those commands in PostScript. Two of the commands that a turtle recognizes are setpos (which moves to an absolute position) and setorientation (which rotates to an absolute direction). My purpose is to implement a logo-style turtle. In other words, I'm looking for an "absolute moveto" instruction that moves to a specific point, not relative to the current translated coordinates. I also want to know how to move to a specific point on the page after a series of rotations and translations. I want something like "0 rotateto" that leaves me at the current location but pointing to the absolute top of the page similarly, "90 rotateto" would point right. The obvious answer is to keep track of what direction I am pointing each time I translate, but that seems like a lot of work. After doing a complicated series of rotations and translations, I want to return the current direction to "North" pointing at the top of the page.
0 Comments
Leave a Reply. |