Skip to content

Polar Axis#4055

Merged
swharden merged 20 commits intoScottPlot:mainfrom
CoderPM2011:feat/Plottables-Polar
Jul 21, 2024
Merged

Polar Axis#4055
swharden merged 20 commits intoScottPlot:mainfrom
CoderPM2011:feat/Plottables-Polar

Conversation

@CoderPM2011
Copy link
Contributor

@CoderPM2011 CoderPM2011 commented Jul 7, 2024

This was originally designed for #3939, but later I decided to develop it into a polar coordinate-based plot because some plots are easier to implement in polar coordinates.

Due to the need to base it on polar coordinates, I have added a lot of related code.
However, I'm unsure whether some of the changes are necessary or appropriate.

The ultimate goal is to make this plot easier to implement,
similar to radar plots, pie plots, or other similar types of plots.


The Polar Plot now functions like a scatter plot on polar coordinates,
using Circular and Radial axes instead of standard X and Y axes.

My test code:

// add sample data
var pts = new PolarCoordinates[] {
    new PolarCoordinates(10, 45),
    new PolarCoordinates(50, 90),
    new PolarCoordinates(30, 127),
    new PolarCoordinates(15, 270),
    new PolarCoordinates(125, 180),
};

var polar = formsPlot1.Plot.Add.Polar(pts);
polar.LegendText = "TEST";

image

@swharden
Copy link
Member

swharden commented Jul 7, 2024

However, I'm unsure whether some of the changes are necessary or appropriate.

Hi @CoderPM2011, I took a quick look and this is looking great! Feel free to create whatever types and interfaces feel right, and I can refine them as needed right before I merge. Let me know when you think this is ready to merge and I'll make those edits and add it to the cookbook! 🚀

Note that the test are failing because the new classes in the Primitives folder should just have the namespace ScottPlot and not ScottPlot.Primitives. Similparly, the new interfaces in the Interfaces folder may be in the ScottPlot namespace, not ScottPlot.Interfaces. Fixing this will probably make the tests pass 👍

@swharden
Copy link
Member

swharden commented Jul 7, 2024

I can refine them as needed right before I merge

I'll make those edits and add it to the cookbook

If you'd rather, I can make some refinements myself by editing the code in this PR, then let you know when I'm done so you can pick it up again. I don't want to start making commits here without you being ready for it though, because merge conflicts inside pull requests can get pretty annoying 🤪

Take as long as you need! I'm putting a lot of time today into #3186

- convert degrees to radians
- convert radians to degrees
- normalize radians to [0, 2π]
- normalize degrees to [0,360]
- angular unit use degrees
- support for converting between polar and Cartesian coordinates
@CoderPM2011 CoderPM2011 force-pushed the feat/Plottables-Polar branch from 515d8af to 8c64f82 Compare July 8, 2024 14:18
@CoderPM2011
Copy link
Contributor Author

The test code is at the bottom.
It is currently possible to adjust the style of any axis line.

I'm not sure if the current axis naming is suitable or easily understandable.

image

My test code:

var pts = new PolarCoordinates[] {
    new PolarCoordinates(10, 45),
    new PolarCoordinates(50, 90),
    new PolarCoordinates(30, 127),
    new PolarCoordinates(15, 270),
    new PolarCoordinates(125, 180),
};

ScottPlot.Plottables.Polar polar = formsPlot1.Plot.Add.Polar(pts);
ScottPlot.Color[] map = new ScottPlot.Colormaps.Turbo()
    .GetColors(polar.CircularAxis.AxisLines.Length);
polar.RadialAxis.Spokes[1].LineStyle.Pattern = LinePattern.Dotted;
polar.RadialAxis.Spokes[1].LineStyle.Width = 3;
polar.RadialAxis.Spokes[1].LineStyle.Color = Colors.Red;

polar.RadialAxis.Spokes[2].LineStyle.Pattern = LinePattern.Dashed;
polar.RadialAxis.Spokes[2].LineStyle.Width = 2;
polar.RadialAxis.Spokes[2].LineStyle.Color = Colors.Silver;

polar.RadialAxis.Spokes[3].LineStyle.Pattern = LinePattern.DenselyDashed;
polar.RadialAxis.Spokes[3].LineStyle.Width = 5;
polar.RadialAxis.Spokes[3].LineStyle.Color = Colors.Purple;

for (int i = 0; i < polar.CircularAxis.AxisLines.Length - 1; i++)
{
    polar.CircularAxis.AxisLines[i].LineStyle.Pattern =
        (i % 2 == 0)
        ? LinePattern.Dotted
        : LinePattern.DenselyDashed;
    polar.CircularAxis.AxisLines[i].LineStyle.Width =
        (i % 2 == 0)
        ? 3
        : 1;
    polar.CircularAxis.AxisLines[i].LineStyle.Color =
        map[i].WithLightness(0.3F);
}
polar.LegendText = "TEST";

var RadialAxisPt = Coordinates.FromPolarCoordinates(130, 300);
for (int i = 0; i < 4; i++)
{
    var RadialAxisPt2 = Coordinates.FromPolarCoordinates(70, 90 * i);
    formsPlot1.Plot.Add.Callout(
        "RadialAxis",
        textLocation: RadialAxisPt.WithDelta(+50, 0),
        tipLocation: RadialAxisPt2);
}

var CircularAxisPt = Coordinates.FromPolarCoordinates(125, 140);
for (int i = 1; i <= 4; i++)
{
    var CircularAxisPt2 = Coordinates.FromPolarCoordinates(125.0 * i / 4.0, 140);
    formsPlot1.Plot.Add.Callout(
        "CircularAxis",
        textLocation: CircularAxisPt.WithDelta(-150, 0),
        tipLocation: CircularAxisPt2);
}

formsPlot1.Update();

@swharden swharden changed the title Added something about polar Polar Plot Jul 20, 2024
@swharden
Copy link
Member

Hi @CoderPM2011, thanks so much for this PR! It took me a while to get to because I was focused entirely on #4053 for the last few weeks, but now that it's merged I'm happy to pick this up now. I'll probably make a few refinements, then merge it just like it is. This is looking great! 🚀

@swharden
Copy link
Member

Heads up, the two major change I'm about to start pushing to this branch are:

  1. Adding cookbook recipes that document much of the functionality. I'm refactoring lightly as I go to maximize simplicity of these recipes.

  2. I may refactor the the "polar plot" (which stores coordinates) to act more like a "polar axis" which only stores information about spoke and circle axis lines. It would have methods to return cartesian coordinates given polar coordinates, then users can use it with all the existing plot types (not just markers, but also lines and polygons)

@swharden
Copy link
Member

swharden commented Jul 20, 2024

Still a work in progress, but you can probably see the direction this is going by looking at the new cookbook recipes!

Thanks again for your work on this! It's looking fantastic! 🚀

@swharden swharden changed the title Polar Plot Polar Axis Jul 21, 2024
@swharden
Copy link
Member

Following-up, I removed some of the functionality from a few of the types that wasn't used (equality checks, implicit operations between polar coordinates and cartesian coordinates, etc.) but if you think it would be useful to other peoples' workflows (code outside ScottPlot) let me know and we can add some of that back in.

Thanks again for this PR @CoderPM2011! It was a pleasure to review today 😄

I'm going to merge it now, but feel free to open new PRs if you recommend refinements and I'll merge those in quickly 🚀

@swharden swharden marked this pull request as ready for review July 21, 2024 01:27
@swharden swharden merged commit 8232e0a into ScottPlot:main Jul 21, 2024
@CoderPM2011 CoderPM2011 deleted the feat/Plottables-Polar branch July 21, 2024 01:42
@CoderPM2011 CoderPM2011 mentioned this pull request Jul 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants