Skip to content

VectorFieldList#2079

Merged
swharden merged 11 commits intomainfrom
2064b
Aug 30, 2022
Merged

VectorFieldList#2079
swharden merged 11 commits intomainfrom
2064b

Conversation

@swharden
Copy link
Member

@swharden swharden commented Aug 30, 2022

The goal of this PR is to create a new plot type which makes it simple to place vector arrows anywhere on the plot (not constrained to a grid like the current VectorField)

image

ScottPlot.Plot plt = new();

// Create a vector field list and add it to the plot
var field = plt.AddVectorFieldList();

// Optionally color arrows using a colormap and custom scaling function
field.Colormap = Colormap.Turbo;
field.ColormapScaler = (magnitude) => magnitude * 5;

// Additional arrow styling options are here
field.ArrowStyle.ScaledArrowheads = true;
field.ArrowStyle.Anchor = ArrowAnchor.Base;
field.ArrowStyle.LineWidth = 3;
field.ArrowStyle.MarkerSize = 10;
field.ArrowStyle.MarkerShape = MarkerShape.filledDiamond;

// Generate random vectors
Random rand = new(0);
int pointCount = 20;
for (int i = 0; i < pointCount + 1; i++)
{
    double x = i / (double)pointCount;
    double y = Math.Sin(i * 2 * Math.PI / pointCount);
    Coordinate coordinate = new(x, y);

    double dX = i / (double)pointCount * .15;
    double dY = i / (double)pointCount * .15;
    CoordinateVector vector = new(dX, dY);

    var rootedVector = (coordinate, vector);
    field.RootedVectors.Add(rootedVector);
}

plt.SaveFig("vectors.png");

@swharden swharden marked this pull request as ready for review August 30, 2022 01:39
@swharden swharden enabled auto-merge August 30, 2022 01:51
@bclehmann
Copy link
Member

I'd also note that it's a little confusing that VectorField and VectorFieldList use different vector objects, and I'm not sure that it's necessary to introduce a new one instead of using Vector2. But I think we discussed this though my COVID-addled brain cannot recall, so feel free to ignore that if you're satisfied we've exhausted that conversation.

@swharden swharden disabled auto-merge August 30, 2022 02:07
@swharden swharden enabled auto-merge August 30, 2022 02:07
@swharden
Copy link
Member Author

a little confusing that VectorField and VectorFieldList use different vector objects

I think the API is different enough (a 2D array vs. part of a tuple) that it's unlikely to cause too much of a problem, but your point is a good one!

I like the custom type (especially the overloads that allow it to add/subtract from Coordinate) that if I were to change anything it would probably be to strangle the Vector2[,] from the original vector field. Actually, maybe we should strangle the whole plot type and create a VectorFieldGrid (giving us one more shot at a simpler API).

Ideas for the future! 🚀 Thanks again for the review 👍

@swharden swharden merged commit 6d9cb48 into main Aug 30, 2022
@swharden swharden deleted the 2064b branch August 30, 2022 02:16
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.

VectorField: support for arbitrary vector positions

2 participants