Recent

Author Topic: TSinCos  (Read 8386 times)

greatUnknown

  • New Member
  • *
  • Posts: 19
TSinCos
« on: August 21, 2012, 11:51:32 pm »
Not meaning to criticize a beautiful and complex piece of work, but it seems
that you call the source once to get the X (radian) values and generate FSin
and FCos, to fill the TAngleArray.  Then you go back a second time to get the
Y (radius) values which you process with FSin and FCos to generate
the final point.X and point.Y values.

Wouldn't it be more efficient to have a TSinCosRadius record, i.e.

  TSinCosRadius = record
     FSin, FCos, Radius : Double;
  end;

which would require only a single call to the source for each point?

Am I missing something?


Ask

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 687
Re: TSinCos
« Reply #1 on: August 22, 2012, 07:38:51 am »
Not meaning to criticize a beautiful and complex piece of work,
Constructive criticism is quite welcome.

you call the source once to get the X (radian) values and generate FSin
and FCos, to fill the TAngleArray.  Then you go back a second time to get the
Y (radius) values which you process with FSin and FCos to generate
the final point.X and point.Y values.
Wouldn't it be more efficient to have a TSinCosRadius record
In the future, please specify which part of the TAChart package you are talking about,
and which Lazarus version.
Here I assume you mean TPolarSeries -- but there is no "TAngleArray" in it.
Anyway, the optimization you propose makes some sense, however:
1) Chart sources may provide multiple Y values (currently, polar series does not support them,
  but this is simply because nobody requested that).
2) For the simplest and most common case of list source,
  the cost of access is actually lower then the cost of duplication. If the source really slow
  there is always an option of using list source as a cache, as demonstrated in db demo.
3) As you can see in the docs, the sequential access to any source is supposed to be relatively
  cheap -- as opposed to random access, which may be slow.

So, in conclusion, the optimization you requested is come complex to do that it seems,
and I will perform it only if there is a compelling use case (which you may well provide, if you have one).

Also, note that polar series is currently in a very basic form because of lack of users.
If you utilize polar series, please share your experiences and possible feature requests.

greatUnknown

  • New Member
  • *
  • Posts: 19
Re: TSinCos
« Reply #2 on: August 22, 2012, 06:06:50 pm »
Thank you; I'm learning...slowly.

The unit was TRadialSeries in TAChart.  My version is RC1.1

The array I mislabelled in my original query is FAngleCache.

Modifications (in a descendent of TPolarSeries) I am working on include

a) Changing TRadialSeries.Draw by changing ADrawer.Polygon to
ADrawer.Polyline.  I was experimenting with archimedian spirals and did not like that
.Polygon closed the figure.  If a boolean "CloseFigure" is set, then Draw ends by
calling  ADrawer.Line (pts [Count -1], pts
  • );


b) creating circular and radial axes.

c) slowing down the draw by breaking the draw routine down into a series of segments,
each separated by winCrt.delay (milliseconds);

Much of this stems from my years teaching basic Calculus; I am trying to use this for
educational purposes.

[If I ever get to it, I am thinking of hyperbolic coordinates and other weirdness, where
the axes themselves are specified by functions.  I'm thinking that TAChart could accept
them as user-defined series.  I do not want to think about axes transformations at this time.]

Question:  I created TAdvPolarSeries = class (TPolarSeries) and inserted it into TRadialSeries just
 after TPolarSeries.  At the end of the unit I added  RegisterSeriesClass(TAdvPolarSeries, 'Adv Polar series');
Everything compiled, but I cannot figure out how to add the class to the series editor for the graph Chart1 (=TChart) .
Which means that when I add a polar series to the graph, it is the original TPolarSeries.

How do I get TAdvPolarSeries and its properties to be recognized by TAChart?
« Last Edit: August 22, 2012, 09:46:07 pm by greatUnknown »

Ask

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 687
Re: TSinCos
« Reply #3 on: August 23, 2012, 05:18:07 am »
Quote
Changing TRadialSeries.Draw by changing ADrawer.Polygon to
ADrawer.Polyline.
(Side note: please try to be more precise -- it is TPolarSeries, not TRadialSeries.
Although it is obvious this time, in more complex situation this can cause misunderstanding. Thanks)
Yes, this makes sense -- I just was lazy in the initial implementation.
Added "CloseCircle" property in r38340. The name is chosen for Delphi compatibility.

Quote
c) slowing down the draw by breaking the draw routine down into a series of segments, each separated by winCrt.delay (milliseconds);
Although in your specific use case (demonstration to a students in a single-application mode) it may be fine, this route is not generally advisable.
Slowing down paint handler will cause issues for the whole UI.
Instead, use Timer to cause periodic redraws of the chart, each redraw
displaying different set of points.
I think a good generic design for such feature would be to introduce TAnimatedChartSource.

Quote
b) creating circular and radial axes.
Quote
hyperbolic coordinates and other weirdness, ... I do not want to think about axes transformations at this time.
Now this is an interesting and complex topic.
There is definitely a users' interest in non-Cartesian axises. Besides obvious polar coordinates, I was recently requested about "ternary" coordinates, and now you suggest hyperbolic.
However, axis and transformations are essentially interlinked -- otherwise,
there would be no point in using different coordinate systems.
So I am still thinking about a good design for the generic case -- if you have any ideas, they are welcome.

Quote
I cannot figure out how to add the class to the series editor for the graph
You should add your changes to the Lazarus itself.
To do this, either modify the original TAChart source an rebuild Lazarus,
or create your own package (http://wiki.freepascal.org/Lazarus_Packages).

AnthonyTekatch

  • Jr. Member
  • **
  • Posts: 78
Re: TSinCos
« Reply #4 on: July 17, 2018, 09:48:52 pm »
b) creating circular and radial axes.

Does anyone know if this is possible (circular and radial axes on a chart) ?

wp

  • Hero Member
  • *****
  • Posts: 11853
Re: TSinCos
« Reply #5 on: July 17, 2018, 10:18:58 pm »

AnthonyTekatch

  • Jr. Member
  • **
  • Posts: 78
Re: TSinCos
« Reply #6 on: July 17, 2018, 11:13:14 pm »

AnthonyTekatch

  • Jr. Member
  • **
  • Posts: 78
Re: TSinCos
« Reply #7 on: July 28, 2018, 01:10:47 pm »
It is not built-in, but you can custom-draw the axes.

Follow the ideas in http://forum.lazarus.freepascal.org/index.php/topic,27248.msg168240.html#msg168240 and http://forum.lazarus.freepascal.org/index.php/topic,16977.msg93141.html#msg93141


Is it possible to have the grid show on top of the plot?

I am using TColormapSeries, and the grid seems to be completely covered up.

As a test, I modified your program to show a filled plot and the grid is hidden behind the plot as shown in my attachment below, but I would like the grid to cover the plot.

wp

  • Hero Member
  • *****
  • Posts: 11853
Re: TSinCos
« Reply #8 on: July 28, 2018, 02:04:50 pm »
Nice - which function is that? Looks like some dipole antenna thing.

The event OnAfterDrawBackwall is called very early, before the series are drawn - therefore, the axis grid is covered by the series.

Alternatively you can use the chart event OnAfterDraw to draw the axes - it is called when all painting is done and will definitely paint over the series. I think that the procedure DrawPolarAxes of the example can be called directly from this event.

Another option would be to set the "Transparency" of the TColorMapSeries to some intermediate value (maybe 128) to let the background shine through. The overall image will have less color saturation, though.
« Last Edit: July 28, 2018, 04:08:47 pm by wp »

AnthonyTekatch

  • Jr. Member
  • **
  • Posts: 78
Re: TSinCos
« Reply #9 on: August 01, 2018, 02:01:43 am »
Nice - which function is that? Loops like some dipole antenna thing.
That screen capture is from the program you linked here:
http://forum.lazarus.freepascal.org/index.php/topic,27248.msg168240.html#msg168240
I just changed the Chart.Chart1PolarSeries1.Filled property to True

Quote
The event OnAfterDrawBackwall is called very early, before the series are drawn - therefore, the axis grid is covered by the series.

Alternatively you can use the chart event OnAfterDraw to draw the axes - it is called when all painting is done and will definitely paint over the series. I think that the procedure DrawPolarAxes of the example can be called directly from this event.

Thank you for your suggestion. I was able to get the grid on top of the plot (see image below) and have made the simple modification to your program (attached below).

440bx

  • Hero Member
  • *****
  • Posts: 3944
Re: TSinCos
« Reply #10 on: August 01, 2018, 03:12:44 am »
I was able to get the grid on top of the plot (see image below) and have made the simple modification to your program (attached below).

Very nice work Anthony.
(FPC v3.0.4 and Lazarus 1.8.2) or (FPC v3.2.2 and Lazarus v3.2) on Windows 7 SP1 64bit.

 

TinyPortal © 2005-2018