简体   繁体   English

如何检测与Python相交的乌龟对象?

[英]How to detect turtle objects intersecting in python?

I'm using turtle and inserting 2 shapes into the program and I am trying to make the program perform a specific function when the objects intersect. 我正在使用turtle并将2个形状插入程序中,并且当对象相交时,我试图使程序执行特定的功能。 Is it possible to do it with an if statement? 是否可以使用if语句呢?

I suspect that the proper answer is "no". 我怀疑正确的答案是“否”。 Turtle graphics does not maintain the shape in a form useful for you to test, nor does it provide shape manipulation methods. Turtle图形不会以对您有用的测试形式保持形状,也未提供形状处理方法。

You could develop your own package to represent objects, and include an intersection method, but this takes a lot of work. 可以开发自己的包来表示对象,并包括一个交集方法,但这需要大量工作。 If you're interested, see the BOOST library shape methods (that's in C++) that Luke Simonson did (2009, I think). 如果您有兴趣,请参阅Luke Simonson(2009,我认为)的BOOST库形状方法(在C ++中)。

However, if your shapes are regular enough, you can make a proximity detector. 但是,如果您的形状足够规则,则可以制作一个接近检测器。 For instance, if the shapes are more or less circular, you could simply see whether they've come within r1 + r2 of each other (a simple distance function on their current positions), where r1 & r2 are the radii of the objects. 例如,如果形状或多或少是圆形的,则可以简单地查看它们是否位于r1 + r2之间(它们当前位置上的简单距离函数),其中r1和r2是对象的半径。 Is that close enough for your purposes? 距离您的目的足够近了吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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