Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. where can find the fastest "LineTO" code? ro how to do!

where can find the fastest "LineTO" code? ro how to do!

Scheduled Pinned Locked Moved C / C++ / MFC
graphicsperformancehelptutorialquestion
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    G Richard
    wrote on last edited by
    #1

    I am working with a drawing program. I want to draw rotated ellipse(I dont't want to use rotated DC),but I fond the pen caps can only be round in win98. So I write "LineTo" myself. But I found its speed was too slow. So please help me, tell where can find fastest code. thanks to all the programmers who have helped me.

    T 1 Reply Last reply
    0
    • G G Richard

      I am working with a drawing program. I want to draw rotated ellipse(I dont't want to use rotated DC),but I fond the pen caps can only be round in win98. So I write "LineTo" myself. But I found its speed was too slow. So please help me, tell where can find fastest code. thanks to all the programmers who have helped me.

      T Offline
      T Offline
      Tomasz Sowinski
      wrote on last edited by
      #2

      You can draw rotated ellipse using approximation with Bezier segments. The code below may be just what you want (I've extracted it from some old app - found the code on the net); the degrees parameter controls the rotation

      void EllipseEx(CDC &dc, int cx, int cy, int rx, int ry, int degrees)
      {
      const int Segments = 12;
      const int PointCount = 1 + 3 * Segments;
      const double Alpha = 3.14159265359 / Segments;
      const double Beta = 4 * (1 - cos(Alpha)) / (3 * sin(Alpha));

      double px\[PointCount\], py\[PointCount\];
      double Angle, CosA, SinA;
      
      for (int i = 0; i < Segments; i ++)
      {
      	Angle = 2 \* i \* Alpha;
      
      	CosA = cos(Angle);
      	SinA = sin(Angle);
      	int k = 3 \* i;
      	int j = (i == 0) ? 3 \* Segments - 1 : k - 1;
      			
      	px\[k\] = rx \* CosA;
      	py\[k\] = ry \* SinA;
      
      	SinA \*= Beta \* rx; //\* SinA;
      	CosA \*= Beta \* ry; //\* CosA;
      
      	px\[j\] = px\[k\] + SinA;
      	py\[j\] = py\[k\] - CosA;
      
      	px\[k + 1\] = px\[k\] - SinA;
      	py\[k + 1\] = py\[k\] + CosA;
      }
      
      px\[PointCount - 1\] = px\[0\];
      py\[PointCount - 1\] = py\[0\];
      
      Angle = 2 \* 3.1415927 \* degrees / 360;
      CosA = cos(Angle); 
      SinA = sin(Angle); 
      
      POINT pt\[PointCount\];
      for (i = 0; i < PointCount; i ++)
      {
      	pt\[i\].x = cx + (LONG)(0.5 + px\[i\] \* CosA - py\[i\] \* SinA);
      	pt\[i\].y = cy + (LONG)(0.5 + px\[i\] \* SinA + py\[i\] \* CosA);
      }
      
      PolyBezier(dc, pt, PointCount); 
      

      }

      Tomasz Sowinski -- http://www.shooltz.com

      G 1 Reply Last reply
      0
      • T Tomasz Sowinski

        You can draw rotated ellipse using approximation with Bezier segments. The code below may be just what you want (I've extracted it from some old app - found the code on the net); the degrees parameter controls the rotation

        void EllipseEx(CDC &dc, int cx, int cy, int rx, int ry, int degrees)
        {
        const int Segments = 12;
        const int PointCount = 1 + 3 * Segments;
        const double Alpha = 3.14159265359 / Segments;
        const double Beta = 4 * (1 - cos(Alpha)) / (3 * sin(Alpha));

        double px\[PointCount\], py\[PointCount\];
        double Angle, CosA, SinA;
        
        for (int i = 0; i < Segments; i ++)
        {
        	Angle = 2 \* i \* Alpha;
        
        	CosA = cos(Angle);
        	SinA = sin(Angle);
        	int k = 3 \* i;
        	int j = (i == 0) ? 3 \* Segments - 1 : k - 1;
        			
        	px\[k\] = rx \* CosA;
        	py\[k\] = ry \* SinA;
        
        	SinA \*= Beta \* rx; //\* SinA;
        	CosA \*= Beta \* ry; //\* CosA;
        
        	px\[j\] = px\[k\] + SinA;
        	py\[j\] = py\[k\] - CosA;
        
        	px\[k + 1\] = px\[k\] - SinA;
        	py\[k + 1\] = py\[k\] + CosA;
        }
        
        px\[PointCount - 1\] = px\[0\];
        py\[PointCount - 1\] = py\[0\];
        
        Angle = 2 \* 3.1415927 \* degrees / 360;
        CosA = cos(Angle); 
        SinA = sin(Angle); 
        
        POINT pt\[PointCount\];
        for (i = 0; i < PointCount; i ++)
        {
        	pt\[i\].x = cx + (LONG)(0.5 + px\[i\] \* CosA - py\[i\] \* SinA);
        	pt\[i\].y = cy + (LONG)(0.5 + px\[i\] \* SinA + py\[i\] \* CosA);
        }
        
        PolyBezier(dc, pt, PointCount); 
        

        }

        Tomasz Sowinski -- http://www.shooltz.com

        G Offline
        G Offline
        G Richard
        wrote on last edited by
        #3

        thank you! Do you have the code of LineTo? Mine is much slower than the CDC::LineTo. And how to create a pen with square cap in win98? thanks to all the programmers who have helped me.

        T 1 Reply Last reply
        0
        • G G Richard

          thank you! Do you have the code of LineTo? Mine is much slower than the CDC::LineTo. And how to create a pen with square cap in win98? thanks to all the programmers who have helped me.

          T Offline
          T Offline
          Tomasz Sowinski
          wrote on last edited by
          #4

          Do you have the code of LineTo? Mine is much slower than the CDC::LineTo. Why do you need your own LineTo? Tomasz Sowinski -- http://www.shooltz.com

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups