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

Added a method mul() #47

Closed
wants to merge 1 commit into from
Closed

Conversation

paperschool
Copy link

This method is for simple multiplication of two vectors

This method is for simple multiplication of two vectors
@jriecken
Copy link
Owner

Can you give an example of where/how this would be used? I haven't really had a use for vectors multiplied this way.

(I think this is called a Hadamard Product)

@paperschool
Copy link
Author

Its an obscure one for sure, usually id use this kind of calculation when applying some kind of friction vector to an velocity vector before applying it to a player position rather than manually multiplying the x's and y's. eg

playerVel.mul(playerAcc);
playerVel.mul(worldFriction);
playerPos.add(playerVel);

Naturally an incomplete description but i think I made the point, also I think I may have made a typo anyway in the function if you do accept it.

@jriecken
Copy link
Owner

jriecken commented Nov 1, 2017

Ah, I think you can do this with the existing scale function (The only difference is that it doesn't directly take in a vector parameter, but individual x and y parameters):

vel.scale(acc.x, acc.y)
vel.scale(friction.x, friction.y)
pos.add(vel)

@jriecken
Copy link
Owner

Given that it's pretty easy to accomplish this by using the scale method, I'm going to close this.

@jriecken jriecken closed this Oct 20, 2018
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.

None yet

2 participants