Transformations on the complex plane

In the complex mode, Decimal BASIC allows a complex function to be defiled, hence a transformation on the complex plane can be defined as a function in BASIC.
But a function cannot be applied to a picture definition, so we write a program in which each drawing command is designated with the transformed points.
In addition, inverse transformation is sometimes useful, but BASIC does not generate a inverse of a function.

Example. The mapping w=z3

When we draw a curve represented by parametric equations, we apply the mapping to each point, and plot the point by separating the coordinates into the real and the imaginary part.
[Note] A curve represented by parametric equations x=f(t), y=g(t) in rectangular coordinates can be represented by a function f(t)+i*g(t).

100 OPTION ARITHMETIC COMPLEX
110 LET i=SQR(-1)
120 DEF F(z)=z^3                 ! Transformation on the complex plane
130 DEF C(t)=-1+(1+2*i)*t        ! parametric curve (or line)
140 SET POINT STYLE 1
150 SET WINDOW -10,10,-10,10
160 DRAW grid
170 FOR t=-10 TO 10 STEP 0.001
180    LET z=C(t)
190    LET w=F(z)
200    SET POINT COLOR 2
210    PLOT POINTS: RE(z),IM(z)
220    SET POINT COLOR 4
230    PLOT POINTS: RE(w),IM(w)
240 NEXT t 
250 END


When we transform an image with the mapping w=z3, we cannot get a good image by plotting the transformed point for each point of the image. In this case, inverse transformation is useful.
We transform a image put on the first quadrant with a map w=z3. As the resulting image spans among the first, second and third quadrants, we find the point z(=u+vi) such that w=z3 for each point w(=x+yi) in the first, second or third quadrant and move the color of z to w.
In the following program, the portion made of lines from 300 to 330 is the inverse function.
The original image is put in the fourth quadrant for the sake of handling.

90 REM 写像w=z^3
100 OPTION ARITHMETIC NATIVE
110 OPTION ANGLE DEGREES
120 SET COLOR MODE "NATIVE"                ! enables true color
130 GLOAD "nya.JPG"                        ! An arbitrary image (BMP, GIF, or JPEG) can be designated here
140 ASK PIXEL SIZE (0,0; 1,1) a,b              ! Find the width and length in pixels
150 DIM p(a,b)                                 ! prepare an array fitting the image size.
160 ASK PIXEL ARRAY (0,1) p                    ! store the colors of each point of the image
170 LET s=MAX(a,b)
180 SET bitmap SIZE 2*s+1,2*s+1
190 CLEAR                                      ! initialize the screen    
200 SET WINDOW -s,s,-s,s                       ! set the coordinate system in pixels
210 LET k=SQR(1/2)                             ! in the logical coordinates, x and y lies between -k and k
220 MAT PLOT CELLS, IN 1,-1 ; a,-b : p         ! moves the original image to the fourth quadrant
230 DRAW grid(0.1, 0.1) WITH SCALE(s/k)        ! draw a grid with  compensation  
240 SET POINT STYLE 1                          ! change the point style to ・
250 FOR xx=-s TO s
260    FOR yy=-s TO s
270       IF xx<0 OR yy>0 THEN                 ! if the point lies in 1,2 or 3 quadrant
280          LET x=xx*k/s                      ! logical x-coordinate
290          LET y=yy*k/s                      ! logical y-coordinate
300          LET r=SQR(x^2+y^2)^(1/3)          ! the cubic root of the absolute
310          LET t=MOD(ANGLE(x,y),360)/3       ! divide the argument by 3
320          LET u=r*COS(t)                    ! logical x-coordinate on the original image
330          LET v=r*SIN(t)                    ! logical x-coordinate on the original image        
340          LET uu=ROUND(u/k*s)               ! convert to pixel coordinate
350          LET vv=ROUND(v/k*s)               ! convert to pixel coordinate
360          IF uu>=1 AND uu<=a AND vv>=1 AND vv<=b THEN
370             ASK PIXEL VALUE (uu, vv-1-b) c 
380             IF c>=0 THEN
390                SET POINT COLOR c
400                PLOT POINTS:xx,yy
410             END IF
420          END IF 
430       END IF
440    NEXT yy
450 NEXT xx
460 END


The original picture was taken from here.

Note.
If the transformation is the map w=zn and 0 < n≦3, we modify lines 300 and 310.
If the transformation is the map w=z4, the original image cannot be put into the fourth quadrant, then the color of a point should be obtained from the two-dimensional array.
In each case, the value k in line 210 must be modified.


Back