where can find the fastest "LineTO" code? ro how to do!
-
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.
-
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.
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
-
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
-
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.
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