문제

I'm trying to figure out a way to determine the relative velocity of a body colliding with another in a 2D environment.

For example if one body is moving at (1,0) and another traveling behind it collides with it from behind at (2,0) the velocity of the impact relative to the first body was (1,0).

I need a method which takes in two velocities, one velocity belonging to the body the velocity is being measured against, and the other for the impacting body and return the relative velocity.

도움이 되었습니까?

해결책

ey? Surely this should be just component 1 of vector 1 -component 1 of vector 2 and component 2 of vector 1 - component 2 of vector 2? Write a method

vector v3 = new vector(v1.x-v2.x, v1.y-v2.y);

In fact, the Vector2 structure has a subtract method that yields this result: vector2 subtract

다른 팁

I don't know what is already in C# but you will benefit from having a Vector library which includes physics. The simple vector libraries will determine relative velocities but if you are doing physics (e.g. particles bouncing) you may need to consider the masses of the particles and to conserve momentum (e.g. what happens when two equal masses with veclocity (1,2) and (-1,3) hit each other. In which case you will need a class which models the mass, position and velocity of every particle. (This is what is done in simulating material made of atoms, for example)

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top