There is a procedure that draws a graph of the parametric function in the Cartesian system. Tell me how to remake for the polar system.

procedure paint_graphics(x0,y0,mx,my:integer); const t_start=0; t_end=20; dt=0.01; var t,x,y:real; xe,ye:integer; begin t:=t_start; repeat x:=f(t); y:=g(t); xe:=trunc(x0+x*mx); ye:=trunc(y0-y*my); PutPixel(xe,ye,5); t:=t+dt; until t>t_end; end; 

he, ye - transfer to the screen coordinates. x0, y0 - the center. t varies from 0 to 20. mx; mu is the scale along the x and y axes.

Can anyone come across?

Now drawn like this:

one

And you need to:

2

Here are the functions themselves:

 const gradus = 0; theta = Pi / 180 * gradus; function f(t:real):real; begin f:=cos(2*t)*cos(theta)-t*sin(theta); end; function g(t:real):real; begin g:=t*cos(theta)+sin(t)*sin(theta); end; 

    2 answers 2

    You need to translate the polar coordinates into Cartesian before output and already draw them.

    Coordinates of the polar system:

    r is the length of the radius of the vector; theta is the angle between the vector and the axis of the abscissa (X).

    Translation to Cartesian:

     x = r * cos(theta) y = r * sin(theta) 

    Actually, everything.

    By the way, your function f (t) returns the radius (calculated using the formula cos (2 * t)), and g (t) returns the angle (the formula is simpler: t).

    • This is probably the whole difficulty: translate x, y to r, theta. - Yuri Zimin
    • You need to translate r and theta to coordinates used on the device =) The screen does not mean anything other than Cartesian. But you can translate. Since the formula is more complicated there, look at ru.wikipedia.org/wiki/Polar coordinate_system - wikipedia. - Alexey Sonkin
    • one
      @ Yuri Zimin Why do you need to translate their Cartesian coordinates into polar? In your case, the objective functions (f & g) take the polar coordinates. It is only necessary to translate the result of these functions into Cartesian coordinates to display them. - IAZ

    If I understand correctly, do I need to convert the code like this? (there is no possibility to check yet)

      procedure paint_graphics(x0,y0,mx,my:integer); const t_start=0; t_end=20; dt=0.01; var t,x,y,r,phi:real; xe,ye:integer; begin t:=t_start; repeat r:=f(t); phi:=g(t); x:=r*cos(phi); { Добавил } y:=r*sin(phi); { Добавил } xe:=trunc(x0+x*mx); ye:=trunc(y0-y*my); PutPixel(xe,ye,5); t:=t+dt; until t>t_end; end;