C#检查C是否在A和B点之间 [英] C# Check if C is in between A and B point

查看:84
本文介绍了C#检查C是否在A和B点之间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好!

我想写一个可以带球投篮的程序.但是有一个小问题,当我拍摄时,我想检查在拍摄开始位置(A)和拍摄结束位置(B)之间是否有人(C).

Hello!

I would like to write a program where you can shoot with balls. But there''s a little problem, when I shoot I want to check that is there someone(C) between the shoot start position(A), and the shoot end position(B).
Any ideas to calculate that?

推荐答案

您的问题的解决方案在于计算C与端点A和B所定义的线之间的距离.您可以在此处阅读如何实现此目标: http://www.topcoder.com/tc?d1= tutorials& d2 = geometry1& module = Static [ ^ ].您必须在该页面上向下滚动一点.

计算出C点到AB线的距离(垂直)后,您现在需要检查的是A半径和C半径之和是否等于或大于计算的距离.如果半径之和小于C与AB的距离,则不会发生碰撞.我的陈述假定点A上的球朝球B的方向射击.如果球B朝A球射击,则必须检查半径B加半径C是否大于或等于C与直线的计算距离AB.

希望这会有所帮助!

还有疑问吗?给我留言.

修改:

如果您还有更多物体可能需要对每个物体执行上述草图算法,则清单中的所有物体均由射手A和目的球B之外的所有球组成.
结束修改


最好的问候,
Manfred
The solution to your problem lies in calculating the distance of C from the line defined by the endpoints A and B. You can read here how this can be achieved:http://www.topcoder.com/tc?d1=tutorials&d2=geometry1&module=Static[^]. You''ll have to scroll down a bit on that page.

When the distance (perpendicular) to line AB has been calculated for point C, all you have to check for now is if the sum of A''s radius and C''s radius are equal or greater than the calculated distance. If the sum of the radii were smaller than the distance of C from AB no collision would take place. My statement assumes that the ball on point A is shot in direction of ball B. If the ball B was shot at A then you''d have to check for radius B plus radius C greater or equal to the calculated distance of C from line AB.

Hope this helps!

Still have doubts? Leave me a comment.

Modification:

If you have more objects that could be in the way you''d have to do the above sketched algorithm for each object where the list is made up of all balls except the shooter ball A and the destination ball B.
End modification


Best regards,
Manfred


像您这样的声音最终将需要这样的 Farseer Physics Engine [ ^ ]-它可以帮助您确定所有事物与其他事物之间的关系.

这可能有助于您创建游戏的视觉部分 Balder-适用于Silverlight,Windows Phone 7,Xna和OpenGL的3D引擎 [ ^ ]

问候
Espen Harlinn
Sounds like you eventually is going to need something like this Farseer Physics Engine[^] - it''s going to help you with where everything is in relation to everything else.

This might help you creating the visual part of the game Balder - 3D engine for Silverlight, Windows Phone 7, Xna and OpenGL[^]

Regards
Espen Harlinn


这篇关于C#检查C是否在A和B点之间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆