简体   繁体   中英

given 2 point and 2 direction how do I know if they intersect?

I am doing some collision test in c#, and I have the following problem.

I have object1 and object2, they move in a direction.

I want to activate an effect only if object1 and object2 are colliding in a certain angle

the data I have

Vector2 object1Position
Vector2 object1Direction
float object1ColliderRadius

Vector2 object2Position
Vector2 object2Direction
float object2ColliderRadius

I already made a test to know if object1 is colliding with object2.

What I miss, is the angle of collision in order to activate or not something else in my code. follow this image . 在此处输入图片说明

The angle is easily calculated from, eg, the dot product . The more interesting question is, if the two collide at all. This depends on the speed, of course. It is easily dealt with by adding an additional dimension. Here you'd put z = t . Using 3D affine geometry, you check if the 3D lines intersect. If yes, the objects with 2D trajectories collide. This is for point objects of course, so in detail you have to check for the closest distance of the lines.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM