Skip to content

Vector Field#3625

Merged
swharden merged 13 commits intoScottPlot:mainfrom
bclehmann:feature/vector-field
Apr 9, 2024
Merged

Vector Field#3625
swharden merged 13 commits intoScottPlot:mainfrom
bclehmann:feature/vector-field

Conversation

@bclehmann
Copy link
Member

This example is lifted from the 4.1 cookbook:

var vectors = new List<RootedCoordinateVector>();
double[] xs = Generate.Consecutive(20, 0.5, -5);
double[] ys = Generate.Consecutive(20, 0.5, -5);
float r = 0.5f;

for (int i = 0; i < xs.Length; i++)
{
    for (int j = 0; j < ys.Length; j++)
    {
        vectors.Add(new RootedCoordinateVector(new(xs[i], ys[j]), new((float)ys[j], -9.81f / r * (float)Math.Sin(xs[i]))));
    }
}

var field = new VectorField(new VectorFieldDataSourceCoordinatesList(vectors));
WpfPlot1.Plot.PlottableList.Add(field);

image

@swharden
Copy link
Member

swharden commented Apr 9, 2024

Thanks @bclehmann, this is a great start! Pulling some convo from Discord (#1966)

I would like at a minimum to have less ugly arrows, a method in the plottable factory, and options to anchor the arrows on their midpoint, rather than the vector tail. Colormap support would be cool too

These are all good extensions for this plot type! I'll review and merge this PR in now, and refinements can be made in future PRs 👍

@swharden
Copy link
Member

swharden commented Apr 9, 2024

Note that I'm renaming RootedCoordinateVector.Tail to RootedCoordinateVector.Point since that location may become decoupled from the position on the arrow in a future revision

@swharden
Copy link
Member

swharden commented Apr 9, 2024

Also (let me know if I'm messing up here) I'm going to rename RootedCoordinateVector.Distance to RootedCoordinateVector.Magnitude because I think that word better matches the concept of a vector, and it may be representing things which are not spatial

@swharden swharden changed the title Vector Field Plottable (WIP) Vector Field Apr 9, 2024
@swharden
Copy link
Member

swharden commented Apr 9, 2024

Also, dang, I'm sorry I just noticed this branch was marked "draft" this whole time 😩 I've been pretty aggressively merging PRs as I see them these days 😅 I hope I didn't mess you up too much by modifying it and merging it this morning...

I'll still merge this now (because my edits expanded the scope a bit beyond vector fields) so that future PRs that refine this behavior can be small and easier to work with.

Thanks again for bringing this new plot type to ScottPlot5! 🚀

@swharden swharden linked an issue Apr 9, 2024 that may be closed by this pull request
@swharden swharden marked this pull request as ready for review April 9, 2024 12:48
@swharden swharden enabled auto-merge April 9, 2024 12:48
@swharden swharden merged commit 3a942ce into ScottPlot:main Apr 9, 2024
@bclehmann
Copy link
Member Author

Also (let me know if I'm messing up here) I'm going to rename RootedCoordinateVector.Distance to RootedCoordinateVector.Magnitude because I think that word better matches the concept of a vector, and it may be representing things which are not spatial

Magnitude is actually what I named it originally but I realized some of our other classes used Distance so I tried to be consistent. And then I learned Vector2 uses Length so I guess consistency is going to be hard.

@bclehmann
Copy link
Member Author

I think the main thing that's missing is in the plottable factory, I don't think it automatically assigns a colour to the vector field (so it will be black by default). I don't think we should release a new version without that, but fortunately that's a 2 minute fix.

I also wonder if the legend should have a little arrow (right now it's just a line, which isn't great). As for all the colourmap stuff, that would be cool and probably pretty easy, but maybe not essential.

@swharden
Copy link
Member

swharden commented Apr 9, 2024

Good points! Thanks for your feedback.

Magnitude is actually what I named it originally but I realized some of our other classes used Distance so I tried to be consistent. And then I learned Vector2 uses Length so I guess consistency is going to be hard.

Now that you mention it, I can see multiple sides to this. Since the RootedCoordinateVector and RootedPixelVector both have a unit baked in (coordinates and pixels), perhaps distance or length makes sense over magnitude.

I think the main thing that's missing is in the plottable factory, I don't think it automatically assigns a colour to the vector field (so it will be black by default). I don't think we should release a new version without that, but fortunately that's a 2 minute fix.

#3630

I also wonder if the legend should have a little arrow (right now it's just a line, which isn't great). As for all the colourmap stuff, that would be cool and probably pretty easy, but maybe not essential.

#3631

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 in ScottPlot 5

2 participants