Help with calculating trajectory

General discussion about LÖVE, Lua, game development, puns, and unicorns.
User avatar
pgimeno
Party member
Posts: 3672
Joined: Sun Oct 18, 2015 2:58 pm

Re: Help with calculating trajectory

Post by pgimeno »

The double radius ball is in fact what is called the Minkowski addition, in this case of two circles. It's a technique often used to calculate and resolve complex collisions, because it turns the collision between two bodies into the collision between a point and a body. The point turns into a line as it moves, and it's easier to calculate the intersection between a line and a shape than between two shapes.

That approach will work just fine.
RNavega
Party member
Posts: 385
Joined: Sun Aug 16, 2020 1:28 pm

Re: Help with calculating trajectory

Post by RNavega »

pgimeno wrote: Fri May 31, 2024 6:51 am The double radius ball is in fact what is called the Minkowski addition, in this case of two circles. It's a technique often used to calculate and resolve complex collisions, because it turns the collision between two bodies into the collision between a point and a body. The point turns into a line as it moves, and it's easier to calculate the intersection between a line and a shape than between two shapes.

That approach will work just fine.
That's cool!
betobala wrote: Fri May 31, 2024 4:45 amI'm trying to invert the normal line, but i can not do it, do u have any tips to help me calculate that?
You have that line segment that goes from the picked point on the imaginary green circle to the center of the colorful ball. You can turn it into a vector by subtracting the desired starting point (the position of the colorful ball center) from both points of the segment --the picked point position and the colorful ball center itself-- which will make it a vector starting from the origin of space (0, 0).
From there, you can normalize it so the direction stays the same but its length is scaled to 1, AKA a unit vector, whose direction happens to be the surface normal of the colorful ball where it's going to be bumped.
You can use that then to reflect the white ball, and if you negate that unit vector (negate its X and Y components), it'll flip in the other direction and can be used as the direction of the colorful ball after it's bumped by the white ball.

Edit: that is, if the components of the normal are (normalX, normalY) then you flip it by using (-normalX, -normalY). This only works if it's really a vector (it starts from the origin of space).
betobala
Prole
Posts: 11
Joined: Sun May 19, 2024 11:37 pm

Re: Help with calculating trajectory

Post by betobala »

RNavega wrote: Fri May 31, 2024 12:57 pm
pgimeno wrote: Fri May 31, 2024 6:51 am The double radius ball is in fact what is called the Minkowski addition, in this case of two circles. It's a technique often used to calculate and resolve complex collisions, because it turns the collision between two bodies into the collision between a point and a body. The point turns into a line as it moves, and it's easier to calculate the intersection between a line and a shape than between two shapes.

That approach will work just fine.
That's cool!
betobala wrote: Fri May 31, 2024 4:45 amI'm trying to invert the normal line, but i can not do it, do u have any tips to help me calculate that?
You have that line segment that goes from the picked point on the imaginary green circle to the center of the colorful ball. You can turn it into a vector by subtracting the desired starting point (the position of the colorful ball center) from both points of the segment --the picked point position and the colorful ball center itself-- which will make it a vector starting from the origin of space (0, 0).
From there, you can normalize it so the direction stays the same but its length is scaled to 1, AKA a unit vector, whose direction happens to be the surface normal of the colorful ball where it's going to be bumped.
You can use that then to reflect the white ball, and if you negate that unit vector (negate its X and Y components), it'll flip in the other direction and can be used as the direction of the colorful ball after it's bumped by the white ball.

Edit: that is, if the components of the normal are (normalX, normalY) then you flip it by using (-normalX, -normalY). This only works if it's really a vector (it starts from the origin of space).
I was missing this part "which will make it a vector starting from the origin of space (0, 0).", thanks
RNavega
Party member
Posts: 385
Joined: Sun Aug 16, 2020 1:28 pm

Re: Help with calculating trajectory

Post by RNavega »

betobala wrote: Thu May 30, 2024 3:08 am My goal is to do something like this: https://imgur.com/a/o4HaceP
Any progress in your pool game? That last demo was cool, all it was missing was some jazzy music in the background :)
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest