TPolarSeries

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Post Reply
MikeC
Newbie
Newbie
Posts: 2
Joined: Mon Jan 07, 2002 5:00 am
Location: Isle of Wight

TPolarSeries

Post by MikeC » Thu Sep 16, 2004 6:12 pm

Does anyone have an algorithm to plot a circle about a non centered point using a TPolarSeries?

Marjan
Site Admin
Site Admin
Posts: 745
Joined: Fri Nov 07, 2003 5:00 am
Location: Slovenia
Contact:

Post by Marjan » Fri Sep 17, 2004 2:34 pm

Hi.

All you have to do is transform values from local coordinate system to global angle,radius. The following code should explain what I meant:

Code: Select all

// angles measured in radians
procedure TransformCoord(const r0,a0: double; var angle, radius: double);
var x,y: double;
begin
  x := r0*cos(a0) + radius*cos(angle);
  y := r0*cos(a0) + radius*sin(angle);
  radius := Sqrt(Sqr(x)+Sqr(y));
  angle := ArcTan2(y,x);
end;

procedure TForm1.FormCreate(Sender: TObject);
var t: Integer;
    r,a: Double;
begin
  Series1.GetVertAxis.SetMinMax(0,200);
  Series1.XValues.Order := loNone;
  // draw circle with radius 25 at r0=100, angle = 2*Pi/3
  for t:= 1 to 20 do
  begin
    // local coordinates
    r := 25;
    a := 2*Pi*t/20.0;
    // transform to global coords
    TransformCoord(100,2*Pi/3.0,a,r);
    // angle to degrees
    a := a* 180.0/Pi;
    Series1.AddPolar(a,r);
  end;
end;
Alternatively, if you only want to draw circle, not related to series points at specific coordinates, all you have to do is manually draw using TChart.Canvas.Circle method in TChart OnAfterDraw event.
Marjan Slatinek,
http://www.steema.com

Post Reply