nalgebra icon indicating copy to clipboard operation
nalgebra copied to clipboard

Generalize center function to any affine combination of points

Open bluthej opened this issue 2 months ago • 1 comments

I have a use case where I need to compute the barycenter of a number of points, with unequal weights, and I would thus find it useful to have a function that would compute any affine combination of a collection of points.

Currently, the way I achieve this is by turning the points into vectors, manually computing the linear combination, and then turning the resulting vector back into a point, but having a convenience function for this in nalgebra would be great!

I'm not entirely sure what API would be most appropriate for this (e.g. taking a slice of points and a slice of weights or an iterator that yields tuples of a point and the associated weight, do we take n points but n-1 weights to ensure that the weights add up to 1 or do we just normalize by the sum of the weights) but before discussing the details I just wanted to see if that's something that the maintainers would accept as a contribution :)

bluthej avatar Nov 03 '25 10:11 bluthej

Given the API design challenges you identified, I'm not sure the implementation is complex enough relative to the API for there to be much benefit providing a helper for this vs. encouraging users to implement whatever behavior they want as you did.

Ralith avatar Nov 03 '25 19:11 Ralith