Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Processing an list vectors at once #127

Open
mllobera opened this issue Nov 15, 2024 · 5 comments
Open

Processing an list vectors at once #127

mllobera opened this issue Nov 15, 2024 · 5 comments

Comments

@mllobera
Copy link

mllobera commented Nov 15, 2024

I could not find this information so I thought I would ask here.

Is there a way to be able to process an array or list of vectors all at once?

So something like,

lst = [Vector3([1,2,3]), ..., Vector3([7,8,9])]
rot_lst = lst * Matrix44.from_x_rotation(radians(90))

I have seen that there is a function matrix44.apply_to_vectors() but I have been unable to get it to work with either a numpy array or a list (also I cannot tell when to use Matrix44 or matrix44? it seems that there are two different set of methods???)

@adamlwgriffiths
Copy link
Owner

Support for mass transforms is inconsistent and depends on the function.
The intention was always to add support for it, but I never got around to it.

A trivial (and slow) way to do it would be detect lists of lists / arrays of arrays, and iterate over them at the function level using a decorator.

@mllobera
Copy link
Author

mllobera commented Nov 15, 2024 via email

@mllobera
Copy link
Author

The following example is a hack but it works to do mass transformation (the price you pay is that you revert back to numpy).

S = Matrix44.from_scale([0.5, -0.5, 1])
R = Matrix44.from_z_rotation(radians(90))
T = Matrix44.from_translation([-100, -100, 0])
t = S * R * T

vecs = np.array([[100.0, 100.0, 0, 1],
                           [200.0, 200.0, 0, 1]])
trans = vecs * np.matrix(t)
trans = np.array(trans)

result

array([[ 0., 0., 0., 1.],
[50., 50., 0., 1.]])

Not ideal but...

@adamlwgriffiths
Copy link
Owner

adamlwgriffiths commented Nov 16, 2024

I haven't tested it, but that should work as is, since the procedural and oo interfaces are just np.arrays. Possibly some of the extra stuff added will cause problems.

Vector3 -> BaseVector3 -> BaseVector -> BaseObject

Alternatively you can just use the procedural API which is literally just np.array.

@mllobera
Copy link
Author

Thanks Adam. I was surprise to see that Matrix44 did not behave as a numpy matrix. By just perusing very quickly through your code, this is explained because , as you point out, matrix inherits from an numpy array and not a numpy matrix. Changing this would represent a huge endeavor but I am wondering whether it would provide a slick way towards providing a way for mass transformations. Just some thoughts...

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

No branches or pull requests

2 participants