Skip to content

Smith Chart: New plot type for displaying impedance on a circular coordinate system#4634

Merged
swharden merged 9 commits intoScottPlot:mainfrom
CoderPM2011:feat/#4578
Jan 4, 2025
Merged

Smith Chart: New plot type for displaying impedance on a circular coordinate system#4634
swharden merged 9 commits intoScottPlot:mainfrom
CoderPM2011:feat/#4578

Conversation

@CoderPM2011
Copy link
Contributor

resolve #4578.
This is just a simple implementation, no other additional content is considered.

I added SmithChartAxis according to the PolarAxis class, so they have a consistent usage concept.

To implement SmithChartAxis, I added Drawing.DrawArc method and extended PolarAxisCircle.

Parts of the SmithChartAxis source code that require attention

static method

  • CalculateGamma
    Convert impedance(R+jX) to Cartesian coordinates (x, y) for display.

axis set method

  • SetConstantRealParts
  • SetConstantImaginaryParts

Plot.Add.SmithChartAxis() actually presets the axis:

SetConstantRealParts([30, 5, 2, 1, 0.5, 0.2, 0]);
SetConstantImaginaryParts([30, 5, 2, 1, 0.5, 0.2, 0.0, -0.2, -0.5, -1, -2, -5, -30]);

demo

image

demo code

SmithChartAxis smithChartAxis = formsPlot1.Plot.Add.SmithChartAxis();
Coordinates[] pts = [
    SmithChartAxis.CalculateGamma(new(1, 30)),
    SmithChartAxis.CalculateGamma(new(1, 5)),
    SmithChartAxis.CalculateGamma(new(1, 2)),
    SmithChartAxis.CalculateGamma(new(1, 1)),
    SmithChartAxis.CalculateGamma(new(1, 0.5)),
    SmithChartAxis.CalculateGamma(new(1, 0.2)),
    SmithChartAxis.CalculateGamma(new(1, 0)),
    SmithChartAxis.CalculateGamma(new(1, -0.2)),
    SmithChartAxis.CalculateGamma(new(1, -0.5)),
    SmithChartAxis.CalculateGamma(new(1, -1)),
    SmithChartAxis.CalculateGamma(new(1, -2)),
    SmithChartAxis.CalculateGamma(new(1, -5)),
    SmithChartAxis.CalculateGamma(new(1, -30)),
    new(1, 0), // at ∞
];
formsPlot1.Plot.Add.Scatter(pts);
formsPlot1.Refresh();

@swharden
Copy link
Member

swharden commented Jan 4, 2025

Hi @CoderPM2011, WOW this is amazing! This is something users have asked for for many years. You did an awesome job here, thanks so much for this! 🚀

Can you clarify something though - when you said "Parts of the SmithChartAxis source code that require attention", did you mean you're not satisfied with the current implementation? Flipping through the code it looks all right to me...

I'll add a few cookbook recipes demonstrating this (committing to this branch), merge it in today, and make an announcement tagging a bunch of old issues and users who asked for this over the years.

@swharden
Copy link
Member

swharden commented Jan 4, 2025

Hi @CoderPM2011, I refined the styling a bit. What do you think of this cookbook recipe?

Can you think of additional recipes that users may find useful while keeping the number of lines of code low?

var smith = myPlot.Add.SmithChartAxis();

// translate an impedance location on the Smith chart to a 2D location on the plot
double resistance = 0.2;
double reactance = -0.5;
Coordinates location = smith.GetCoordinates(resistance, reactance);

// use that location to add traditional plot components
myPlot.Add.Marker(location, MarkerShape.FilledCircle, size: 15, Colors.Red);
var txt = myPlot.Add.Text("0.2 - j 0.5", location);
txt.LabelStyle.FontSize = 24;
txt.LabelStyle.Bold = true;
txt.LabelStyle.ForeColor = Colors.Red;

image

@swharden swharden changed the title Added SmithChartAxis Smith Chart: New plot type for displaying impedance on a circular coordinate system Jan 4, 2025
@swharden swharden enabled auto-merge (squash) January 4, 2025 19:46
@swharden swharden merged commit 9c77a2e into ScottPlot:main Jan 4, 2025
3 checks passed
@CoderPM2011
Copy link
Contributor Author

Can you clarify something though - when you said "Parts of the SmithChartAxis source code that require attention", did you mean you're not satisfied with the current implementation? Flipping through the code it looks all right to me...

Sorry for the misunderstanding. 😅
Because the coordinate system of SmithChartAxis is different from the general one, if you don’t know those methods, you may not be able to draw the required graphics.

@CoderPM2011 CoderPM2011 deleted the feat/#4578 branch January 5, 2025 01:51
@CoderPM2011
Copy link
Contributor Author

@swharden this looks good👍

I'm not very familiar with this kind of picture so don't have any more use case ideas at the moment. 😥

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.

Is it possible to plot the smith chart with ScottPlot library?

2 participants