SlideShare a Scribd company logo
1 of 36
Download to read offline
A
                                   L TEX
                Geometria Computacional
                          Primeiros GDs
                          Escalonamento
                                  Curvas
                    Inventing the Wheel
                    Show Off: Os Oids...




                  Geometria Computacional

         Ole Peter Smith, IME, UFG, ole@mat.ufg.br


                              Dia Debian
                          UEG, UnU Laranjeiras
                              17/08/2012


                  Life sure is a Mystery to be Lived
                    Not a Problem to be Solved...

Ole Peter Smith, IME, UFG, ole@mat.ufg.br   Geometria Computacional
A
                                   L TEX
                Geometria Computacional
                          Primeiros GDs
                          Escalonamento
                                  Curvas
                    Inventing the Wheel
                    Show Off: Os Oids...




Beautiful Scientific Documents
Classical Free Software
Markup Language
Thesis, automatic:
· Bibliography
· Contents
· List of Tables, Figures
· Index, References

                                                    SL!
Slideshows: Beamer
MikTex, LyX, TexMaker, Kyle



Ole Peter Smith, IME, UFG, ole@mat.ufg.br   Geometria Computacional
A
                                   L TEX
                Geometria Computacional
                          Primeiros GDs
                                            Geometria Computacional
                          Escalonamento
                                            GD
                                  Curvas
                    Inventing the Wheel
                    Show Off: Os Oids...




Quero Desenhar µατ µατ ικα...
Usando SL...
Graphical Library
· GD
· Unices - Ruindows
· PHP - C - Perl - ...
· http://www.libgd.org/Documentation
· http://www.php.net/manual/pt BR/book.image.php
Formats: GIF - PNG - JPG
    Animated GIF’s
    GIF’s: poucas cores


Ole Peter Smith, IME, UFG, ole@mat.ufg.br   Geometria Computacional
A
                                   L TEX
                Geometria Computacional
                          Primeiros GDs
                                            Geometria Computacional
                          Escalonamento
                                            GD
                                  Curvas
                    Inventing the Wheel
                    Show Off: Os Oids...




Estrutura:
$image=CreateImageObject;
$image− >DrawSomething;
...
$image− >WriteImage;
$image− >Close;
Pixels...




Ole Peter Smith, IME, UFG, ole@mat.ufg.br   Geometria Computacional
A
                                         L TEX
                      Geometria Computacional     Init Image Object
                                Primeiros GDs     Email as Icon
                                Escalonamento     Draw Line I
                                        Curvas    Problem
                          Inventing the Wheel     Draw Line II
                          Show Off: Os Oids...


Init Image Object (PHP)
      ImageCreate:
      $image = imagecreate (400,400)or die ("Cannot Create image")
      #Black on White - Background first!
      $bg_color = imagecolorallocate ($image,255, 255, 255);
      $text_color = imagecolorallocate ($image,0,0,0);

      Tell Apache to Expect an Image
      header("Content-type: image/png");

      Draw a Line
      imageline($image,10,20,100,200,$text_color);

      Close and Write
      imagepng ($image);
      Ole Peter Smith, IME, UFG, ole@mat.ufg.br   Geometria Computacional
A
                                          L TEX
                       Geometria Computacional     Init Image Object
                                 Primeiros GDs     Email as Icon
                                 Escalonamento     Draw Line I
                                         Curvas    Problem
                           Inventing the Wheel     Draw Line II
                           Show Off: Os Oids...


Never Publish Emails on www

   $id=$_GET["ID"];
   $person=Mysql_SelectUniqueHash("People","ID=’".$id."’");
   $email=$person[ "Email" ];
   header("Content-type: image/png");
   $hgt=imagefontheight(3);
   $wdt=imagefontwidth(3*strlen($email);
   $image = ImageCreate ($wdt+10, $hgt+10)
            or die ("Cannot Create image");
   $bg_color = imagecolorallocate ($image,255, 255, 255);
   $text_color = imagecolorallocate ($image,34,139,34);
   imagecolortransparent($image,$bg_color);
   imagestring ($image,$fontsize, 5, 5, $email, $text_color);
   imagepng ($image);

       Ole Peter Smith, IME, UFG, ole@mat.ufg.br   Geometria Computacional
A
                                         L TEX
                      Geometria Computacional     Init Image Object
                                Primeiros GDs     Email as Icon
                                Escalonamento     Draw Line I
                                        Curvas    Problem
                          Inventing the Wheel     Draw Line II
                          Show Off: Os Oids...


Draw Line

      Draw Line: y = x + 1, x ∈ [0, 5]
      $image = imagecreate (400,400)
               or die ("Cannot Create image");
      #Black on White - Background first!
      $bg_color = imagecolorallocate ($image,255, 255, 255);
      $text_color = imagecolorallocate ($image,0,0,0);

      header("Content-type: image/png");
      imageline($image,0,1,5,6,$text_color);
      imagepng ($image);


      Ole Peter Smith, IME, UFG, ole@mat.ufg.br   Geometria Computacional
A
                                          L TEX
                       Geometria Computacional     Init Image Object
                                 Primeiros GDs     Email as Icon
                                 Escalonamento     Draw Line I
                                         Curvas    Problem
                           Inventing the Wheel     Draw Line II
                           Show Off: Os Oids...


Draw Line I - Result




       Ole Peter Smith, IME, UFG, ole@mat.ufg.br   Geometria Computacional
A
                                         L TEX
                      Geometria Computacional     Init Image Object
                                Primeiros GDs     Email as Icon
                                Escalonamento     Draw Line I
                                        Curvas    Problem
                          Inventing the Wheel     Draw Line II
                          Show Off: Os Oids...


Draw Line I - Problem
      Escalonamento!
      Flipped: Cima por baixo...
      Draw Point: filledarc
      void imagearc($im,
                       int $cx, int $cy,      #center
                       int $a, $int b,        #semi-eixos
                       int $ang1, int $ang2, #angle (degrees)
                       int $color);
      void imagefilledarc($im,
                              int $cx, int $cy,
                              int $a, int $b,
                              int $ang1, int $ang2,
                              int $color,int $style);
      Ole Peter Smith, IME, UFG, ole@mat.ufg.br   Geometria Computacional
A
                                          L TEX
                       Geometria Computacional     Init Image Object
                                 Primeiros GDs     Email as Icon
                                 Escalonamento     Draw Line I
                                         Curvas    Problem
                           Inventing the Wheel     Draw Line II
                           Show Off: Os Oids...


Draw Line II

   $im=imagecreate (400,400);
   $bgcol = imagecolorallocate ($im,255, 255, 255);
   $txtcol = imagecolorallocate ($im,0,0,0);
   header("Content-type: image/png");
   imagestring($im,5,15+8,15-5,"1",$txtcol);
   imagefilledarc($im,15,15,10,10,0,360,$txtcol,IMG_ARC_PIE);
   imagefilledarc($im,200,200,50,100,0,90,$txtcol,IMG_ARC_PIE)
   imagestring($im,5,385+8,385-5,"2",$txtcol);
   imagefilledarc($im,385,385,10,10,0,360,$txtcol,IMG_ARC_PIE)
   imagepng($im);


       Ole Peter Smith, IME, UFG, ole@mat.ufg.br   Geometria Computacional
A
                                          L TEX
                       Geometria Computacional     Init Image Object
                                 Primeiros GDs     Email as Icon
                                 Escalonamento     Draw Line I
                                         Curvas    Problem
                           Inventing the Wheel     Draw Line II
                           Show Off: Os Oids...


Draw Line II - Result




       Ole Peter Smith, IME, UFG, ole@mat.ufg.br   Geometria Computacional
A
                                             L TEX
                                                      Scaling
                          Geometria Computacional
                                                      Programmed
                                    Primeiros GDs
                                                      Initialization
                                    Escalonamento
                                                      Convertion
                                            Curvas
                                                      Now Draw
                              Inventing the Wheel
                                                      Convertions
                              Show Off: Os Oids...


Scaling

          Rx , Ry ∈ N: Ex. 400,400
          Minx , Miny ∈ R: 0.0,0.0
          Maxx , Maxy ∈ R: 6.0,6.0
          Affin Application:
                                          X               ax x + bx
                                                  =
                                          Y               ay y + by
          Conditions:
             0                 ax Minx + bx                      Rx             ax Maxx + bx
                   =                                  ,                 =
            Ry                 ay Miny + by                      0              ay Maxy + by


          Ole Peter Smith, IME, UFG, ole@mat.ufg.br   Geometria Computacional
A
                                             L TEX
                                                      Scaling
                          Geometria Computacional
                                                      Programmed
                                    Primeiros GDs
                                                      Initialization
                                    Escalonamento
                                                      Convertion
                                            Curvas
                                                      Now Draw
                              Inventing the Wheel
                                                      Convertions
                              Show Off: Os Oids...


Scaling



          ax (Maxx − Minx ) = Rx − 0 ∧ ay (Maxy − Miny ) = 0 − Ry ⇔
                    Rx                      Ry
          ax =               ∧ ay = −
               Maxx − Minx            Maxy − Miny
          bx = −ax Minx
          by = −ay Maxy




          Ole Peter Smith, IME, UFG, ole@mat.ufg.br   Geometria Computacional
A
                                           L TEX
                                                    Scaling
                        Geometria Computacional
                                                    Programmed
                                  Primeiros GDs
                                                    Initialization
                                  Escalonamento
                                                    Convertion
                                          Curvas
                                                    Now Draw
                            Inventing the Wheel
                                                    Convertions
                            Show Off: Os Oids...


Scaling - Init

       function InitCanvas($R,$Min,$Max)
       {
          global $a,$b;
          $a=array();$b=array();

             $a[0]=$R[0]/($Max[0]-$Min[0]);
             $a[1]=-$R[1]/($Max[1]-$Min[1]);

             $b[0]=-$a[0]*$Min[0];
             $b[1]=$a[1]*$Max[1];
       }

        Ole Peter Smith, IME, UFG, ole@mat.ufg.br   Geometria Computacional
A
                                          L TEX
                                                   Scaling
                       Geometria Computacional
                                                   Programmed
                                 Primeiros GDs
                                                   Initialization
                                 Escalonamento
                                                   Convertion
                                         Curvas
                                                   Now Draw
                           Inventing the Wheel
                                                   Convertions
                           Show Off: Os Oids...


Scaling - Convertion

       function ScalePoint($p)
       {
          global $a,$b;

            $pp=array();
            for ($i=0;$i<2;$i++)
            {
               $pp[$i]=((int) ($a[$i]*$p[$i]+$b[$i]));
            }

            return $pp;
       }
       Ole Peter Smith, IME, UFG, ole@mat.ufg.br   Geometria Computacional
A
                                         L TEX
                                                  Scaling
                      Geometria Computacional
                                                  Programmed
                                Primeiros GDs
                                                  Initialization
                                Escalonamento
                                                  Convertion
                                        Curvas
                                                  Now Draw
                          Inventing the Wheel
                                                  Convertions
                          Show Off: Os Oids...


Now Draw the Line....


      $Res=array(400,400);
      $Min=array(0.0,0.0);
      $Max=array(6.0,6.0);
      InitCanvas($R,$Min,$Max);
      $p1=array(0.0,1.0);
      $p2=array(5.0,6.0);
      $pp1=ScalePoint($p1);
      $pp2=ScalePoint($p2);
      imageline($pp1[0],$pp1[1],$pp2[0],$pp2[1],$color);



      Ole Peter Smith, IME, UFG, ole@mat.ufg.br   Geometria Computacional
A
                                          L TEX
                                                   Scaling
                       Geometria Computacional
                                                   Programmed
                                 Primeiros GDs
                                                   Initialization
                                 Escalonamento
                                                   Convertion
                                         Curvas
                                                   Now Draw
                           Inventing the Wheel
                                                   Convertions
                           Show Off: Os Oids...


Draw Line I - Result




       Ole Peter Smith, IME, UFG, ole@mat.ufg.br   Geometria Computacional
A
                                          L TEX
                                                   Scaling
                       Geometria Computacional
                                                   Programmed
                                 Primeiros GDs
                                                   Initialization
                                 Escalonamento
                                                   Convertion
                                         Curvas
                                                   Now Draw
                           Inventing the Wheel
                                                   Convertions
                           Show Off: Os Oids...


Serial Convertion

       Maligma: C´digo Repetido
                 o
       function ScalePoints($ps)
       {
          $pps=array();
          for ($n=0;$n<count($ps);$n++)
          {
             $pps[$n]=ScalePoint($ps[$n]);
          }

            return $pps;
       }

       Ole Peter Smith, IME, UFG, ole@mat.ufg.br   Geometria Computacional
A
                                          L TEX
                       Geometria Computacional     Drawing a Circle
                                 Primeiros GDs     Generate
                                 Escalonamento     Line Segments
                                         Curvas    Code
                           Inventing the Wheel     Results
                           Show Off: Os Oids...


Drawing a Circle


      Equation:

                                 (x − xc )2 + (y − yc )2 = r 2
      Parametrization:

                                   x(t)              xc + r cos t
                                               =
                                   y (t)             yc + r sin t
      t ∈ [−π, π]



       Ole Peter Smith, IME, UFG, ole@mat.ufg.br   Geometria Computacional
A
                                          L TEX
                       Geometria Computacional     Drawing a Circle
                                 Primeiros GDs     Generate
                                 Escalonamento     Line Segments
                                         Curvas    Code
                           Inventing the Wheel     Results
                           Show Off: Os Oids...


Generating a Circle

       function Circle($n,$pc,$r,$ang=0.0)
       {
          $dt=2*3.1415927/(1.0*($n-1));
          $ps=array();
          for ($i=0,$t=$ang;$i<$n;$i++,$t+=$dt)
          {
             $p=array( $pc[0]+$r*cos($t),$pc[1]+$r*sin($t) );
             array_push($ps,$p);
          }
          return $ps;
       }

       Ole Peter Smith, IME, UFG, ole@mat.ufg.br   Geometria Computacional
A
                                         L TEX
                      Geometria Computacional     Drawing a Circle
                                Primeiros GDs     Generate
                                Escalonamento     Line Segments
                                        Curvas    Code
                          Inventing the Wheel     Results
                          Show Off: Os Oids...


Curve as Line Segments
      function DrawCurve($im,$ps,$color)
      {
         $pps=ScalePoints($ps);
         for ($n=0;$n<count($pps)-1;$n++)
         {
            imageline
            (
               $im,
               $pps[$n][0],$pps[$n][1],
               $pps[$n+1][0],$pps[$n+1][1],
               $color
            );
         }
      Ole Peter Smith, IME, UFG, ole@mat.ufg.br   Geometria Computacional
A
                                          L TEX
                       Geometria Computacional     Drawing a Circle
                                 Primeiros GDs     Generate
                                 Escalonamento     Line Segments
                                         Curvas    Code
                           Inventing the Wheel     Results
                           Show Off: Os Oids...


Drawing Circle



      $n=6;
      $center=array(2.0,1.0);
      $ps=Circle($n,$center,2);
      DrawCurve($im,$ps,$color);
      imagestring($im,3,5,5,"n=$n",$color);




       Ole Peter Smith, IME, UFG, ole@mat.ufg.br   Geometria Computacional
A
                                          L TEX
                       Geometria Computacional     Drawing a Circle
                                 Primeiros GDs     Generate
                                 Escalonamento     Line Segments
                                         Curvas    Code
                           Inventing the Wheel     Results
                           Show Off: Os Oids...


Draw Circle - Result n = 6




       Ole Peter Smith, IME, UFG, ole@mat.ufg.br   Geometria Computacional
A
                                          L TEX
                       Geometria Computacional     Drawing a Circle
                                 Primeiros GDs     Generate
                                 Escalonamento     Line Segments
                                         Curvas    Code
                           Inventing the Wheel     Results
                           Show Off: Os Oids...


Draw Circle - Result n = 20




       Ole Peter Smith, IME, UFG, ole@mat.ufg.br   Geometria Computacional
A
                                          L TEX
                       Geometria Computacional     Drawing a Circle
                                 Primeiros GDs     Generate
                                 Escalonamento     Line Segments
                                         Curvas    Code
                           Inventing the Wheel     Results
                           Show Off: Os Oids...


Draw Circle - Result n = 500




       Ole Peter Smith, IME, UFG, ole@mat.ufg.br   Geometria Computacional
A
                                          L TEX
                       Geometria Computacional
                                 Primeiros GDs     Drawing a Wheel
                                 Escalonamento     Animate...
                                         Curvas    Solution
                           Inventing the Wheel
                           Show Off: Os Oids...


Drawing a Wheel
  function DrawWheel($im,$n,$dn,$pc,$r1,$r2,$color,$ang=0.0)
  {
     $p1s=Circle($n,$pc,$r1,$ang);
     DrawCurve($im,$p1s,$color);
     $p2s=Circle($n,$pc,$r2,$ang);
     DrawCurve($im,$p2s,$color);

      for ($i=0;$i<$n;$i+=$dn)
      {
         $p1=ScalePoint($p1s[$i]);
         $p2=ScalePoint($p2s[$i]);
         imageline($im,$p1[0],$p1[1],$p2[0],$p2[1],$color);
      }
  }
       Ole Peter Smith, IME, UFG, ole@mat.ufg.br   Geometria Computacional
A
                                         L TEX
                      Geometria Computacional
                                Primeiros GDs     Drawing a Wheel
                                Escalonamento     Animate...
                                        Curvas    Solution
                          Inventing the Wheel
                          Show Off: Os Oids...


Drawing a Wheel




      $n=200;
      $dn=5;
      $center=array(2.0,1.0);
      DrawWheel($im,$n,$dn,$center,$color,3.0,0.2);




      Ole Peter Smith, IME, UFG, ole@mat.ufg.br   Geometria Computacional
A
                                         L TEX
                      Geometria Computacional
                                Primeiros GDs     Drawing a Wheel
                                Escalonamento     Animate...
                                        Curvas    Solution
                          Inventing the Wheel
                          Show Off: Os Oids...


Wheel - Result




      Ole Peter Smith, IME, UFG, ole@mat.ufg.br   Geometria Computacional
A
                                         L TEX
                      Geometria Computacional
                                Primeiros GDs     Drawing a Wheel
                                Escalonamento     Animate...
                                        Curvas    Solution
                          Inventing the Wheel
                          Show Off: Os Oids...


Animate Wheel

      $nimages=79;
      $dt=2.0*3.1415927/$nimages;
      system("/bin/rm Wheel*.gif");
      for ($t=0.0,$i=0;$i<$nimages;$i++)
      {
         $image = ImageCreate...
         $center=array(3.0,3.0);
         DrawWheel($image,200,5,$center,0.2,2.0,$color,$t);
         imagegif($image,"Wheel.$i.gif");
         $t+=$dt;
      }
      //Merda! PHP nao tem suporte para GIF animado...
      Ole Peter Smith, IME, UFG, ole@mat.ufg.br   Geometria Computacional
A
                                         L TEX
                      Geometria Computacional
                                Primeiros GDs     Drawing a Wheel
                                Escalonamento     Animate...
                                        Curvas    Solution
                          Inventing the Wheel
                          Show Off: Os Oids...


Animate Wheel


      ImageMagick...
      Continued...
      system("/usr/bin/convert -delay 2 -loop 0 ".
             "Wheel.*.gif Wheel.gif");
      header("Content-type: text/html");
      print "<IMG SRC=’Wheel.gif’>n";
      uruacu/Wheel.gif




      Ole Peter Smith, IME, UFG, ole@mat.ufg.br   Geometria Computacional
A
                                             L TEX
                          Geometria Computacional
                                    Primeiros GDs
                                    Escalonamento
                                            Curvas
                              Inventing the Wheel
                              Show Off: Os Oids...


Cycloid




   Icons/Cycloid.gif

          Ole Peter Smith, IME, UFG, ole@mat.ufg.br   Geometria Computacional
A
                                          L TEX
                       Geometria Computacional
                                 Primeiros GDs
                                 Escalonamento
                                         Curvas
                           Inventing the Wheel
                           Show Off: Os Oids...


Trochoid




   Icons/Trochoid_1.gif

       Ole Peter Smith, IME, UFG, ole@mat.ufg.br   Geometria Computacional
A
                                          L TEX
                       Geometria Computacional
                                 Primeiros GDs
                                 Escalonamento
                                         Curvas
                           Inventing the Wheel
                           Show Off: Os Oids...


Trochoid




   Icons/Trochoid_2.gif

       Ole Peter Smith, IME, UFG, ole@mat.ufg.br   Geometria Computacional
A
                                          L TEX
                       Geometria Computacional
                                 Primeiros GDs
                                 Escalonamento
                                         Curvas
                           Inventing the Wheel
                           Show Off: Os Oids...


Epicycloid




   Icons/Epicycloid_1.gif
   Icons/Epicycloid_2.gif
       Ole Peter Smith, IME, UFG, ole@mat.ufg.br   Geometria Computacional
A
                                          L TEX
                       Geometria Computacional
                                 Primeiros GDs
                                 Escalonamento
                                         Curvas
                           Inventing the Wheel
                           Show Off: Os Oids...


Hypocycloid




   Icons/Hypocycloid_1.gif
   Icons/Hypocycloid_2.gif
       Ole Peter Smith, IME, UFG, ole@mat.ufg.br   Geometria Computacional
A
                                           L TEX
                        Geometria Computacional
                                  Primeiros GDs
                                  Escalonamento
                                          Curvas
                            Inventing the Wheel
                            Show Off: Os Oids...


Oloid




   Icons/Oloid.gif
   Please Always Enjoy... Animations - Made in C++
        Ole Peter Smith, IME, UFG, ole@mat.ufg.br   Geometria Computacional

More Related Content

Viewers also liked (12)

Januaria
JanuariaJanuaria
Januaria
 
Prince_3
Prince_3Prince_3
Prince_3
 
Závěrečný úkol KPI
Závěrečný úkol KPIZávěrečný úkol KPI
Závěrečný úkol KPI
 
Goias
GoiasGoias
Goias
 
Fisl
FislFisl
Fisl
 
Prístup k právu eu
Prístup k právu euPrístup k právu eu
Prístup k právu eu
 
Prince[1]
Prince[1]Prince[1]
Prince[1]
 
Dia.debian 2013, Trinidade-GO
Dia.debian 2013, Trinidade-GODia.debian 2013, Trinidade-GO
Dia.debian 2013, Trinidade-GO
 
Përparësitë e ATM-së (Bankomatit)
Përparësitë e ATM-së (Bankomatit)Përparësitë e ATM-së (Bankomatit)
Përparësitë e ATM-së (Bankomatit)
 
Matja e cilësisë!
Matja e cilësisë!Matja e cilësisë!
Matja e cilësisë!
 
Pyetsorë Statistikë
Pyetsorë StatistikëPyetsorë Statistikë
Pyetsorë Statistikë
 
Procesi i shitjes!
Procesi i shitjes!Procesi i shitjes!
Procesi i shitjes!
 

More from Ole Peter Smith (14)

Provas Algebra Linear, Gabaritos
Provas Algebra Linear, GabaritosProvas Algebra Linear, Gabaritos
Provas Algebra Linear, Gabaritos
 
Provas Algebra Linear
Provas Algebra LinearProvas Algebra Linear
Provas Algebra Linear
 
Formas quadraticas
Formas quadraticasFormas quadraticas
Formas quadraticas
 
Notas.al
Notas.alNotas.al
Notas.al
 
Compendio.algebra.linear
Compendio.algebra.linearCompendio.algebra.linear
Compendio.algebra.linear
 
Wi.ufpr
Wi.ufprWi.ufpr
Wi.ufpr
 
Tcp50.jatai
Tcp50.jataiTcp50.jatai
Tcp50.jatai
 
Tcp50.jatai.2
Tcp50.jatai.2Tcp50.jatai.2
Tcp50.jatai.2
 
Unesp
UnespUnesp
Unesp
 
Ditados
DitadosDitados
Ditados
 
Frel.vv
Frel.vvFrel.vv
Frel.vv
 
Provas.gabaritos.2010
Provas.gabaritos.2010Provas.gabaritos.2010
Provas.gabaritos.2010
 
Provas.2010
Provas.2010Provas.2010
Provas.2010
 
Frel.vv
Frel.vvFrel.vv
Frel.vv
 

Gc.d day

  • 1. A L TEX Geometria Computacional Primeiros GDs Escalonamento Curvas Inventing the Wheel Show Off: Os Oids... Geometria Computacional Ole Peter Smith, IME, UFG, ole@mat.ufg.br Dia Debian UEG, UnU Laranjeiras 17/08/2012 Life sure is a Mystery to be Lived Not a Problem to be Solved... Ole Peter Smith, IME, UFG, ole@mat.ufg.br Geometria Computacional
  • 2. A L TEX Geometria Computacional Primeiros GDs Escalonamento Curvas Inventing the Wheel Show Off: Os Oids... Beautiful Scientific Documents Classical Free Software Markup Language Thesis, automatic: · Bibliography · Contents · List of Tables, Figures · Index, References SL! Slideshows: Beamer MikTex, LyX, TexMaker, Kyle Ole Peter Smith, IME, UFG, ole@mat.ufg.br Geometria Computacional
  • 3. A L TEX Geometria Computacional Primeiros GDs Geometria Computacional Escalonamento GD Curvas Inventing the Wheel Show Off: Os Oids... Quero Desenhar µατ µατ ικα... Usando SL... Graphical Library · GD · Unices - Ruindows · PHP - C - Perl - ... · http://www.libgd.org/Documentation · http://www.php.net/manual/pt BR/book.image.php Formats: GIF - PNG - JPG Animated GIF’s GIF’s: poucas cores Ole Peter Smith, IME, UFG, ole@mat.ufg.br Geometria Computacional
  • 4. A L TEX Geometria Computacional Primeiros GDs Geometria Computacional Escalonamento GD Curvas Inventing the Wheel Show Off: Os Oids... Estrutura: $image=CreateImageObject; $image− >DrawSomething; ... $image− >WriteImage; $image− >Close; Pixels... Ole Peter Smith, IME, UFG, ole@mat.ufg.br Geometria Computacional
  • 5. A L TEX Geometria Computacional Init Image Object Primeiros GDs Email as Icon Escalonamento Draw Line I Curvas Problem Inventing the Wheel Draw Line II Show Off: Os Oids... Init Image Object (PHP) ImageCreate: $image = imagecreate (400,400)or die ("Cannot Create image") #Black on White - Background first! $bg_color = imagecolorallocate ($image,255, 255, 255); $text_color = imagecolorallocate ($image,0,0,0); Tell Apache to Expect an Image header("Content-type: image/png"); Draw a Line imageline($image,10,20,100,200,$text_color); Close and Write imagepng ($image); Ole Peter Smith, IME, UFG, ole@mat.ufg.br Geometria Computacional
  • 6. A L TEX Geometria Computacional Init Image Object Primeiros GDs Email as Icon Escalonamento Draw Line I Curvas Problem Inventing the Wheel Draw Line II Show Off: Os Oids... Never Publish Emails on www $id=$_GET["ID"]; $person=Mysql_SelectUniqueHash("People","ID=’".$id."’"); $email=$person[ "Email" ]; header("Content-type: image/png"); $hgt=imagefontheight(3); $wdt=imagefontwidth(3*strlen($email); $image = ImageCreate ($wdt+10, $hgt+10) or die ("Cannot Create image"); $bg_color = imagecolorallocate ($image,255, 255, 255); $text_color = imagecolorallocate ($image,34,139,34); imagecolortransparent($image,$bg_color); imagestring ($image,$fontsize, 5, 5, $email, $text_color); imagepng ($image); Ole Peter Smith, IME, UFG, ole@mat.ufg.br Geometria Computacional
  • 7. A L TEX Geometria Computacional Init Image Object Primeiros GDs Email as Icon Escalonamento Draw Line I Curvas Problem Inventing the Wheel Draw Line II Show Off: Os Oids... Draw Line Draw Line: y = x + 1, x ∈ [0, 5] $image = imagecreate (400,400) or die ("Cannot Create image"); #Black on White - Background first! $bg_color = imagecolorallocate ($image,255, 255, 255); $text_color = imagecolorallocate ($image,0,0,0); header("Content-type: image/png"); imageline($image,0,1,5,6,$text_color); imagepng ($image); Ole Peter Smith, IME, UFG, ole@mat.ufg.br Geometria Computacional
  • 8. A L TEX Geometria Computacional Init Image Object Primeiros GDs Email as Icon Escalonamento Draw Line I Curvas Problem Inventing the Wheel Draw Line II Show Off: Os Oids... Draw Line I - Result Ole Peter Smith, IME, UFG, ole@mat.ufg.br Geometria Computacional
  • 9. A L TEX Geometria Computacional Init Image Object Primeiros GDs Email as Icon Escalonamento Draw Line I Curvas Problem Inventing the Wheel Draw Line II Show Off: Os Oids... Draw Line I - Problem Escalonamento! Flipped: Cima por baixo... Draw Point: filledarc void imagearc($im, int $cx, int $cy, #center int $a, $int b, #semi-eixos int $ang1, int $ang2, #angle (degrees) int $color); void imagefilledarc($im, int $cx, int $cy, int $a, int $b, int $ang1, int $ang2, int $color,int $style); Ole Peter Smith, IME, UFG, ole@mat.ufg.br Geometria Computacional
  • 10. A L TEX Geometria Computacional Init Image Object Primeiros GDs Email as Icon Escalonamento Draw Line I Curvas Problem Inventing the Wheel Draw Line II Show Off: Os Oids... Draw Line II $im=imagecreate (400,400); $bgcol = imagecolorallocate ($im,255, 255, 255); $txtcol = imagecolorallocate ($im,0,0,0); header("Content-type: image/png"); imagestring($im,5,15+8,15-5,"1",$txtcol); imagefilledarc($im,15,15,10,10,0,360,$txtcol,IMG_ARC_PIE); imagefilledarc($im,200,200,50,100,0,90,$txtcol,IMG_ARC_PIE) imagestring($im,5,385+8,385-5,"2",$txtcol); imagefilledarc($im,385,385,10,10,0,360,$txtcol,IMG_ARC_PIE) imagepng($im); Ole Peter Smith, IME, UFG, ole@mat.ufg.br Geometria Computacional
  • 11. A L TEX Geometria Computacional Init Image Object Primeiros GDs Email as Icon Escalonamento Draw Line I Curvas Problem Inventing the Wheel Draw Line II Show Off: Os Oids... Draw Line II - Result Ole Peter Smith, IME, UFG, ole@mat.ufg.br Geometria Computacional
  • 12. A L TEX Scaling Geometria Computacional Programmed Primeiros GDs Initialization Escalonamento Convertion Curvas Now Draw Inventing the Wheel Convertions Show Off: Os Oids... Scaling Rx , Ry ∈ N: Ex. 400,400 Minx , Miny ∈ R: 0.0,0.0 Maxx , Maxy ∈ R: 6.0,6.0 Affin Application: X ax x + bx = Y ay y + by Conditions: 0 ax Minx + bx Rx ax Maxx + bx = , = Ry ay Miny + by 0 ay Maxy + by Ole Peter Smith, IME, UFG, ole@mat.ufg.br Geometria Computacional
  • 13. A L TEX Scaling Geometria Computacional Programmed Primeiros GDs Initialization Escalonamento Convertion Curvas Now Draw Inventing the Wheel Convertions Show Off: Os Oids... Scaling ax (Maxx − Minx ) = Rx − 0 ∧ ay (Maxy − Miny ) = 0 − Ry ⇔ Rx Ry ax = ∧ ay = − Maxx − Minx Maxy − Miny bx = −ax Minx by = −ay Maxy Ole Peter Smith, IME, UFG, ole@mat.ufg.br Geometria Computacional
  • 14. A L TEX Scaling Geometria Computacional Programmed Primeiros GDs Initialization Escalonamento Convertion Curvas Now Draw Inventing the Wheel Convertions Show Off: Os Oids... Scaling - Init function InitCanvas($R,$Min,$Max) { global $a,$b; $a=array();$b=array(); $a[0]=$R[0]/($Max[0]-$Min[0]); $a[1]=-$R[1]/($Max[1]-$Min[1]); $b[0]=-$a[0]*$Min[0]; $b[1]=$a[1]*$Max[1]; } Ole Peter Smith, IME, UFG, ole@mat.ufg.br Geometria Computacional
  • 15. A L TEX Scaling Geometria Computacional Programmed Primeiros GDs Initialization Escalonamento Convertion Curvas Now Draw Inventing the Wheel Convertions Show Off: Os Oids... Scaling - Convertion function ScalePoint($p) { global $a,$b; $pp=array(); for ($i=0;$i<2;$i++) { $pp[$i]=((int) ($a[$i]*$p[$i]+$b[$i])); } return $pp; } Ole Peter Smith, IME, UFG, ole@mat.ufg.br Geometria Computacional
  • 16. A L TEX Scaling Geometria Computacional Programmed Primeiros GDs Initialization Escalonamento Convertion Curvas Now Draw Inventing the Wheel Convertions Show Off: Os Oids... Now Draw the Line.... $Res=array(400,400); $Min=array(0.0,0.0); $Max=array(6.0,6.0); InitCanvas($R,$Min,$Max); $p1=array(0.0,1.0); $p2=array(5.0,6.0); $pp1=ScalePoint($p1); $pp2=ScalePoint($p2); imageline($pp1[0],$pp1[1],$pp2[0],$pp2[1],$color); Ole Peter Smith, IME, UFG, ole@mat.ufg.br Geometria Computacional
  • 17. A L TEX Scaling Geometria Computacional Programmed Primeiros GDs Initialization Escalonamento Convertion Curvas Now Draw Inventing the Wheel Convertions Show Off: Os Oids... Draw Line I - Result Ole Peter Smith, IME, UFG, ole@mat.ufg.br Geometria Computacional
  • 18. A L TEX Scaling Geometria Computacional Programmed Primeiros GDs Initialization Escalonamento Convertion Curvas Now Draw Inventing the Wheel Convertions Show Off: Os Oids... Serial Convertion Maligma: C´digo Repetido o function ScalePoints($ps) { $pps=array(); for ($n=0;$n<count($ps);$n++) { $pps[$n]=ScalePoint($ps[$n]); } return $pps; } Ole Peter Smith, IME, UFG, ole@mat.ufg.br Geometria Computacional
  • 19. A L TEX Geometria Computacional Drawing a Circle Primeiros GDs Generate Escalonamento Line Segments Curvas Code Inventing the Wheel Results Show Off: Os Oids... Drawing a Circle Equation: (x − xc )2 + (y − yc )2 = r 2 Parametrization: x(t) xc + r cos t = y (t) yc + r sin t t ∈ [−π, π] Ole Peter Smith, IME, UFG, ole@mat.ufg.br Geometria Computacional
  • 20. A L TEX Geometria Computacional Drawing a Circle Primeiros GDs Generate Escalonamento Line Segments Curvas Code Inventing the Wheel Results Show Off: Os Oids... Generating a Circle function Circle($n,$pc,$r,$ang=0.0) { $dt=2*3.1415927/(1.0*($n-1)); $ps=array(); for ($i=0,$t=$ang;$i<$n;$i++,$t+=$dt) { $p=array( $pc[0]+$r*cos($t),$pc[1]+$r*sin($t) ); array_push($ps,$p); } return $ps; } Ole Peter Smith, IME, UFG, ole@mat.ufg.br Geometria Computacional
  • 21. A L TEX Geometria Computacional Drawing a Circle Primeiros GDs Generate Escalonamento Line Segments Curvas Code Inventing the Wheel Results Show Off: Os Oids... Curve as Line Segments function DrawCurve($im,$ps,$color) { $pps=ScalePoints($ps); for ($n=0;$n<count($pps)-1;$n++) { imageline ( $im, $pps[$n][0],$pps[$n][1], $pps[$n+1][0],$pps[$n+1][1], $color ); } Ole Peter Smith, IME, UFG, ole@mat.ufg.br Geometria Computacional
  • 22. A L TEX Geometria Computacional Drawing a Circle Primeiros GDs Generate Escalonamento Line Segments Curvas Code Inventing the Wheel Results Show Off: Os Oids... Drawing Circle $n=6; $center=array(2.0,1.0); $ps=Circle($n,$center,2); DrawCurve($im,$ps,$color); imagestring($im,3,5,5,"n=$n",$color); Ole Peter Smith, IME, UFG, ole@mat.ufg.br Geometria Computacional
  • 23. A L TEX Geometria Computacional Drawing a Circle Primeiros GDs Generate Escalonamento Line Segments Curvas Code Inventing the Wheel Results Show Off: Os Oids... Draw Circle - Result n = 6 Ole Peter Smith, IME, UFG, ole@mat.ufg.br Geometria Computacional
  • 24. A L TEX Geometria Computacional Drawing a Circle Primeiros GDs Generate Escalonamento Line Segments Curvas Code Inventing the Wheel Results Show Off: Os Oids... Draw Circle - Result n = 20 Ole Peter Smith, IME, UFG, ole@mat.ufg.br Geometria Computacional
  • 25. A L TEX Geometria Computacional Drawing a Circle Primeiros GDs Generate Escalonamento Line Segments Curvas Code Inventing the Wheel Results Show Off: Os Oids... Draw Circle - Result n = 500 Ole Peter Smith, IME, UFG, ole@mat.ufg.br Geometria Computacional
  • 26. A L TEX Geometria Computacional Primeiros GDs Drawing a Wheel Escalonamento Animate... Curvas Solution Inventing the Wheel Show Off: Os Oids... Drawing a Wheel function DrawWheel($im,$n,$dn,$pc,$r1,$r2,$color,$ang=0.0) { $p1s=Circle($n,$pc,$r1,$ang); DrawCurve($im,$p1s,$color); $p2s=Circle($n,$pc,$r2,$ang); DrawCurve($im,$p2s,$color); for ($i=0;$i<$n;$i+=$dn) { $p1=ScalePoint($p1s[$i]); $p2=ScalePoint($p2s[$i]); imageline($im,$p1[0],$p1[1],$p2[0],$p2[1],$color); } } Ole Peter Smith, IME, UFG, ole@mat.ufg.br Geometria Computacional
  • 27. A L TEX Geometria Computacional Primeiros GDs Drawing a Wheel Escalonamento Animate... Curvas Solution Inventing the Wheel Show Off: Os Oids... Drawing a Wheel $n=200; $dn=5; $center=array(2.0,1.0); DrawWheel($im,$n,$dn,$center,$color,3.0,0.2); Ole Peter Smith, IME, UFG, ole@mat.ufg.br Geometria Computacional
  • 28. A L TEX Geometria Computacional Primeiros GDs Drawing a Wheel Escalonamento Animate... Curvas Solution Inventing the Wheel Show Off: Os Oids... Wheel - Result Ole Peter Smith, IME, UFG, ole@mat.ufg.br Geometria Computacional
  • 29. A L TEX Geometria Computacional Primeiros GDs Drawing a Wheel Escalonamento Animate... Curvas Solution Inventing the Wheel Show Off: Os Oids... Animate Wheel $nimages=79; $dt=2.0*3.1415927/$nimages; system("/bin/rm Wheel*.gif"); for ($t=0.0,$i=0;$i<$nimages;$i++) { $image = ImageCreate... $center=array(3.0,3.0); DrawWheel($image,200,5,$center,0.2,2.0,$color,$t); imagegif($image,"Wheel.$i.gif"); $t+=$dt; } //Merda! PHP nao tem suporte para GIF animado... Ole Peter Smith, IME, UFG, ole@mat.ufg.br Geometria Computacional
  • 30. A L TEX Geometria Computacional Primeiros GDs Drawing a Wheel Escalonamento Animate... Curvas Solution Inventing the Wheel Show Off: Os Oids... Animate Wheel ImageMagick... Continued... system("/usr/bin/convert -delay 2 -loop 0 ". "Wheel.*.gif Wheel.gif"); header("Content-type: text/html"); print "<IMG SRC=’Wheel.gif’>n"; uruacu/Wheel.gif Ole Peter Smith, IME, UFG, ole@mat.ufg.br Geometria Computacional
  • 31. A L TEX Geometria Computacional Primeiros GDs Escalonamento Curvas Inventing the Wheel Show Off: Os Oids... Cycloid Icons/Cycloid.gif Ole Peter Smith, IME, UFG, ole@mat.ufg.br Geometria Computacional
  • 32. A L TEX Geometria Computacional Primeiros GDs Escalonamento Curvas Inventing the Wheel Show Off: Os Oids... Trochoid Icons/Trochoid_1.gif Ole Peter Smith, IME, UFG, ole@mat.ufg.br Geometria Computacional
  • 33. A L TEX Geometria Computacional Primeiros GDs Escalonamento Curvas Inventing the Wheel Show Off: Os Oids... Trochoid Icons/Trochoid_2.gif Ole Peter Smith, IME, UFG, ole@mat.ufg.br Geometria Computacional
  • 34. A L TEX Geometria Computacional Primeiros GDs Escalonamento Curvas Inventing the Wheel Show Off: Os Oids... Epicycloid Icons/Epicycloid_1.gif Icons/Epicycloid_2.gif Ole Peter Smith, IME, UFG, ole@mat.ufg.br Geometria Computacional
  • 35. A L TEX Geometria Computacional Primeiros GDs Escalonamento Curvas Inventing the Wheel Show Off: Os Oids... Hypocycloid Icons/Hypocycloid_1.gif Icons/Hypocycloid_2.gif Ole Peter Smith, IME, UFG, ole@mat.ufg.br Geometria Computacional
  • 36. A L TEX Geometria Computacional Primeiros GDs Escalonamento Curvas Inventing the Wheel Show Off: Os Oids... Oloid Icons/Oloid.gif Please Always Enjoy... Animations - Made in C++ Ole Peter Smith, IME, UFG, ole@mat.ufg.br Geometria Computacional