Welcome, Guest. Please login or register.

Login with username, password and session length

 
Advanced search

1411512 Posts in 69376 Topics- by 58431 Members - Latest Member: Bohdan_Zoshchenko

April 27, 2024, 06:20:11 AM

Need hosting? Check out Digital Ocean
(more details in this thread)
TIGSource ForumsDeveloperTechnical (Moderator: ThemsAllTook)Probably a simple geometry problem.
Pages: [1]
Print
Author Topic: Probably a simple geometry problem.  (Read 3063 times)
ஒழுக்கின்மை (Paul Eres)
Level 10
*****


Also known as रिंकू.


View Profile WWW
« on: April 17, 2009, 04:27:42 PM »

How do you reverse left/right direction, given the current direction? That is, what's the formula for taking a direction and reversing it with respect to a vertical wall.

/ would become \

_ would stay _

| would stay |

this would also happen (if the bounce were against a horizontal wall): ^

I know, this is not phrased very clearly, but hopefully someone will be able to understand and suggest something.
« Last Edit: April 20, 2009, 05:04:28 PM by Derek » Logged

andy wolff
Level 10
*****


-------


View Profile
« Reply #1 on: April 17, 2009, 04:34:16 PM »

normally you would multiply the horizontal component by negative 1 for a vertical wall or the vertical component by -1 for a horizontal floor/ceiling, then recalculate the direction based on your components

also this would work
 180-direction for a wall to the left
 0-direction for a wall to the right
 90-direction for a wall above
 270-direction for a wall below
something like that
Logged

ஒழுக்கின்மை (Paul Eres)
Level 10
*****


Also known as रिंकू.


View Profile WWW
« Reply #2 on: April 17, 2009, 04:38:07 PM »

Excellent, thanks! Will try that.
Logged

raigan
Level 5
*****


View Profile
« Reply #3 on: April 18, 2009, 05:01:57 AM »

The general solution is to split your direction vector into two parts, one parallel to the wall and one perpendicular; to "bounce" you then just negate the perpendicular component and add it to the parallel component to get the new vector.

In the case of axis-aligned walls the decomposition is already done for you by the coordinate system, but in general you need to do a bit of geometry to decompose and re-assemble the direction vector.
Logged
ஒழுக்கின்மை (Paul Eres)
Level 10
*****


Also known as रिंकू.


View Profile WWW
« Reply #4 on: April 18, 2009, 07:26:23 AM »

What is a direction vector? What is a vector in general?
Logged

JoeHonkie
Level 8
***


RIP Major Sebastian Bludd


View Profile WWW
« Reply #5 on: April 18, 2009, 07:30:59 AM »

What is a direction vector? What is a vector in general?
Some guys have linked me some good stuff on this in this thread:
http://forums.tigsource.com/index.php?topic=5800.0
Logged
increpare
Guest
« Reply #6 on: April 18, 2009, 07:33:02 AM »

Quote
What is a direction vector?
instead of encoding directions as angles, use arrows that point in a particular direction  (so north would be (0,1), north-west would be (-1,1)).  It's traditional* to scale the arrows so that their length is 1 (so north-west would be written as (-1/root2,1/root2)).  

If you store them like this, flipping vertically just means negating the first coordinate.

Quote
What is a vector in general?
You probably don't want to know.

[*and there're good reasons why]
« Last Edit: April 18, 2009, 07:41:50 AM by stephen lavelle » Logged
mirosurabu
Guest
« Reply #7 on: April 18, 2009, 07:42:42 AM »



How do you represent direction? Usually, directions are represented using vectors - x and y components of direction. If direction is represented using its x and y components [ x ][ y ] than negative vector (reverse direction) would be [ -x ][ -y ].
Logged
andy wolff
Level 10
*****


-------


View Profile
« Reply #8 on: April 18, 2009, 08:27:16 AM »

the x component of a vector is simply length*cos(angle) while the y component is length*sin(angle), and the angle of an x and y component is tan-1(y/x)
Logged

Alex May
...is probably drunk right now.
Level 10
*


hen hao wan


View Profile WWW
« Reply #9 on: April 18, 2009, 09:55:45 AM »

Actually defining a vector by angle and length is still fine and still a vector, it's just in a different coordinate system (polar as opposed to cartesian).

The maths for reversing a polar coordinate vector in that manner would be simple I think: just make the angle negative (and then if necessary add on 360 degrees to keep it 0 < angle < 360)

(for reflection against other angles (where the angle in the above example is zero) I expect you'd do something like angle = -(angle - wall angle) off the top of my head)
Logged

Movius
Guest
« Reply #10 on: April 18, 2009, 10:05:28 AM »

(for reflection against other angles (where the angle in the above example is zero) I expect you'd do something like angle = -(angle - wall angle) off the top of my head)
newAngle = wallAngle - (OldAngle - wallAngle) = 2*wallAngle - oldAngle

otherwise correct to my extremely-tired brain.
Logged
moi
Level 10
*****


DILF SANTA


View Profile WWW
« Reply #11 on: April 18, 2009, 10:08:25 AM »

Think of vector as coordinates (x,y). Can be 3D (x,y,z)
Other things that are useful to know:
-pythagorus theorem
-relation of sinus and cosinus to an angle

That's all.
Logged

subsystems   subsystems   subsystems
JLJac
Level 10
*****



View Profile
« Reply #12 on: April 18, 2009, 11:08:42 AM »

You define your speed vector as a point, containing x and y floats.

When hitting a vertical surface the x-component of the speed vector is flipped (multiplyed with -1) and the same goes for the y-component when hitting a horizontal surface.
Logged
Zaphos
Guest
« Reply #13 on: April 18, 2009, 11:52:23 AM »

(for reflection against other angles (where the angle in the above example is zero) I expect you'd do something like angle = -(angle - wall angle) off the top of my head)
newAngle = wallAngle - (OldAngle - wallAngle) = 2*wallAngle - oldAngle

otherwise correct to my extremely-tired brain.
I might call that wallNormal instead of wallAngle, in that it's 90 degrees off from the direction the wall is going ...
Logged
Movius
Guest
« Reply #14 on: April 19, 2009, 04:09:19 AM »

It's worth noting that you may not even need "vector maths" (beyond storing position and velocity as (x,y) pairs,) in many situations. any elastic collisions involving walls that are vertical, horizontal or at any 45 degree angle can be calculated using only existing x and y velocity values and the negative sign.

(for reflection against other angles (where the angle in the above example is zero) I expect you'd do something like angle = -(angle - wall angle) off the top of my head)
newAngle = wallAngle - (OldAngle - wallAngle) = 2*wallAngle - oldAngle

otherwise correct to my extremely-tired brain.
I might call that wallNormal instead of wallAngle, in that it's 90 degrees off from the direction the wall is going ...
what he said
Logged
Pages: [1]
Print
Jump to:  

Theme orange-lt created by panic