How to draw a rotated ellipse at a specific angle (Views: 30)
Problem/Question/Abstract: I'm looking for an algorithm that draws an ellipse, but is not based on the Bresenham mid-point method. I want to specify the bounding box and the algorithm should draw the ellipse. As I need to do things for each pixel on the line of the ellipse, I can not use the Windows.Ellipse(dc...) function. Does anyone have such an algorithm? Answer: The procdure draws an rotated ellipse at a specific angle: procedure TForm1.EllipseAngle(ACanvas: TCanvas; XCenter, YCenter, XRadius, YRadius: Integer; Angle: Integer); const Step = 49; var RX, RY: Integer; i: Integer; Theta: Double; SAngle, CAngle: Double; RotAngle: Double; XC, YC: Integer; Kf: Double; X, Y: Double; XRot, YRot: Integer; Points: array[0..Step] of TPoint; begin RotAngle := Angle * PI / 180; Kf := (360 * PI / 180) / Step; SAngle := Sin(RotAngle); CAngle := Cos(RotAngle); for i := 0 to Step do begin Theta := i * Kf; X := XCenter + XRadius * Cos(Theta); Y := YCenter + YRadius * Sin(Theta); XRot := Round(XCenter + (X - XCenter) * CAngle - (Y - YCenter) * SAngle); YRot := Round(YCenter + (X - XCenter) * SAngle + (Y - YCenter) * CAngle); Points[i] := Point(XRot, YRot); end; ACanvas.Polygon(Points); end; |