delphi3000.com - the free delphi knowledge platform
delphi3000.com - the free delphi knowledge platform
497 Users Online NOW
Have a look at your member-status

connecting people's knowledge


  - Recent ArticlesRSS feed for Recent Articles on delphi3000.com
  - List of All Articles
  - Top Viewed Articles
  - Articles (+Attachem.)
  - Articles Of Interest
  - Categories
  - Top Uploader
  - Search
  - Index

  - My Home
  - Submit an Article
  - My Articles
  - My Personal Data
  - My Bookmarks
  - Activities
  - Login/Logout

  - Sign Up
  - Why Sign Up
  - Newsletter

  - Press
  - Advertise

  - Contact
  - Feedback





Community
Borland
ClubeDelphi
Dr. Bob
UK-BUG
Delphi Meetings
Planeta Delphi



Loremo - the 1.5 liter car coming in 2009




Startblatt.de






Share this article with friendsShare this article with friends
Rate this articleRate this article - to keep the quality of delphi3000.com !
Comment this article or read through previous comments (2)


Rotate an ellipseFormat this article printer-friendly!Bookmark function is only available for registered users!
Ellipse with Beziercurves
Product:
Delphi all versions
Category:
Graphic
Skill Level:
Scoring:
Last Update:
06/02/2002
Search Keys:
delphi delphi3000 article borland vcl code-snippet Ellipse Beziercurves Rotate2DPoint
Times Scored:
3
Visits:
3335
Uploader: Holger Voigt
Company: Mediakueche
Reference: N/A
 
Question/Problem/Abstract:
How to draw a rotated Ellipse?
Answer:



I wrote a procedure "CentralRotatedEllipse" to rotate an ellipse. It works exactly enougth for simple graphics. The Ellipse is maked with two connected beziercurves. Rotatingpoint of the Ellipse is its centralpoint. The Parameter canvas for the Destinationcanvas, coordinates  like "common" Ellipse and in alpha the rotatingangle. The function "Rotate2DPoint" you have to put in your code too, its called by the CentralRotatedEllipse-Procedure.
And dont forget uses Math!

enjoy it


  function Rotate2DPoint(P,Fix :TPoint; alpha:double): TPoint;
  var
    sinus, cosinus : Extended;
  begin
    SinCos(alpha, sinus, cosinus);
    P.x := P.x - Fix.x;
    P.y := P.y - Fix.y;
    result.x := Round(p.x*cosinus + p.y*sinus)  +  fix.x ;
    result.y := Round(-p.x*sinus + p.y*cosinus) +  Fix.y;
  end;

  procedure CentralRotatedEllipse(Canvas : TCanvas; x1, y1, x2, y2:Integer; alpha : Extended);
  var PointList: array[0..6] of TPoint;  f : TPoint;  dk : Integer;
  begin
    dk := Round(0.654 * Abs(y2-y1));
    f.x := x1 + (x2-x1) div 2;
    f.y := (y1 + (y2-y1) div 2) -1;
    PointList[0] := Rotate2DPoint(Point(x1, f.y), f, Alpha) ;  // Startpoint
    PointList[1] := Rotate2DPoint(Point(x1,  f.y - dk), f, Alpha);  
    //Controlpoint of Startpoint first part
    PointList[2] := Rotate2DPoint(Point(x2- 1,  f.y - dk), f, Alpha);  
    //Controlpoint of secondpoint first part
    PointList[3] := Rotate2DPoint(Point(x2 -1 , f.y), f, Alpha);
    // Firstpoint of secondpart
    PointList[4] := Rotate2DPoint(Point(x2-1 , f.y + dk), f, Alpha);  
    // Controllpoint of secondpart firstpoint
    PointList[5] := Rotate2DPoint(Point(x1, f.y +  dk), f, Alpha);  
    // Conrollpoint of secondpart endpoint
    PointList[6] := PointList[0];   // Endpoint of
     // Back to the startpoint
    PolyBezier(canvas.handle, Pointlist[0], 7);
  end;





Please rate this article!
Skill level:
BeginnerExpert

Useful:
No!Very!

Overall rating:
PoorExcellent



Comments to this article
Write a new comment
Rotating by wrong angles
    Dmitri Papichev (Jun 3 2002 9:23PM)

If you try the code below, you will see that ellipses drawn are rotated by incorrect angles, looks like 0, 60, 120 degrees correspondingly:

CentralRotatedEllipse (Canvas, 100, 100, 150, 300, 0);
CentralRotatedEllipse (Canvas, 100, 100, 150, 300, 45);
CentralRotatedEllipse (Canvas, 100, 100, 150, 300, 90);

Respond

RE: Rotating by wrong angles
Holger Voigt (Jun 4 2002 10:56AM)

try it in this way below because you have to give the Angle in Rad:

CentralRotatedEllipse (Canvas, 100, 100, 150, 300, DegToRad(45));
CentralRotatedEllipse (Canvas, 100, 100, 150, 300, DegToRad(90));
Respond














 
Sign up to consume product discounts for Bronze memberships !

read more


  Visit our Sponsor

 

  Community Ad of
E. Irigoyen
 
   














 







     
  Copyright © 2000 - 2007 delphi3000.com - All rights reserved. Terms of use. || Privacy
delphi3000.com is a service by bluestep.com IT-Services GmbH (Vienna)