Page 1 of 1

TCrossFunction -- can I get the returnvalue of the crosspoint?

Posted: Fri Mar 03, 2023 3:09 pm
by 16592373
series 1 and series2 is crossing .. but how do I get the value of the cross point

Re: TCrossFunction -- can I get the returnvalue of the crosspoint?

Posted: Fri Mar 03, 2023 4:52 pm
by 16595372
Do i understand correctly that the first point in the parent series is the first cross point?

Code: Select all

repeat
        if LinesCross(index1,index2,x,y) then
           ParentSeries.AddXY(x,y);

Re: TCrossFunction -- can I get the returnvalue of the crosspoint?

Posted: Mon Mar 06, 2023 10:57 am
by yeray
Hello,

Yes, the series you assign the TCrossPointsFunction to contains the crossing points.
Ie:
Project1_2023-03-06_12-00-21.png
Project1_2023-03-06_12-00-21.png (27.65 KiB) Viewed 24486 times

Code: Select all

uses Vcl.StdCtrls, VCLTee.TeeGDIPlus, VCLTee.Chart, VCLTee.Series, VCLTee.StatChar;

var Chart1: TChart;
    line1, line2: TLineSeries;
    crossFunction: TCrossPointsFunction;
    crossPoints: TPointSeries;
    Memo1: TMemo;

procedure TForm1.FormCreate(Sender: TObject);
var i: Integer;
begin
  Chart1:=TChart.Create(Self);
  Chart1.Parent:=Self;
  Chart1.Align:=alClient;
  Chart1.View3D:=False;
  Chart1.Legend.Hide;

  Memo1:=TMemo.Create(Self);
  Memo1.Parent:=Self;
  Memo1.Align:=alRight;

  line1:=TLineSeries(Chart1.AddSeries(TLineSeries));
  line2:=TLineSeries(Chart1.AddSeries(TLineSeries));
  line1.FillSampleValues;
  line2.FillSampleValues;

  crossFunction:=TCrossPointsFunction.Create(Self);
  crossPoints:=TPointSeries(Chart1.AddSeries(TPointSeries));
  crossPoints.Pointer.Size:=2;
  crossPoints.FunctionType:=crossFunction;
  crossPoints.DataSources.Add(line1);
  crossPoints.DataSources.Add(line2);

  Memo1.Lines.Add('Crossing Points:');
  with crossPoints do
    for i:=0 to Count-1 do
      Memo1.Lines.Add('X: '+FormatFloat(ValueFormat, XValues[i])+', Y: '+FormatFloat(ValueFormat, YValues[i]));
end;

Re: TCrossFunction -- can I get the returnvalue of the crosspoint?

Posted: Tue Mar 07, 2023 12:06 pm
by 16592373
thanks ..clear! but..

where exactly is the trigger for the final painting of the chart and lines.

I try to debug step by step in Tee9New.. but get lost.

is it here?

------ from Base Form---------------

ncGDIPlus : if not (Chart1.Canvas is TGLCanvas) then // <-- For demos with default OpenGL Canvas, do not change it !
if not (Chart1.Canvas is TGDIPlusCanvas) then // <-- Do not assign a GDI+ canvas if it already is !
Chart1.Canvas:=TGDIPlusCanvas.Create;
{$ENDIF}
else
Chart1.Canvas:=TTeeCanvas3D.Create;

Re: TCrossFunction -- can I get the returnvalue of the crosspoint?

Posted: Tue Mar 07, 2023 2:30 pm
by yeray
Hello,

I'm not sure what are you trying to achieve.
In the example I posted above, the calculation of the crossing points starts as soon as the second series is added to the crossPoints DataSources.