龟线相交,坐标 [英] Turtle line intersection, coordinates

查看:99
本文介绍了龟线相交,坐标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要制作一个小程序,该程序绘制三个圆圈,即前两个圆圈之间的直线,然后确定第三个圆圈是否与该直线相交或相交。除了最后一部分,我已经做了所有事情。我正在尝试使用这些点来确定面积是否为0,这实际上意味着第三个点与该线相交。对?或者我可以使用另一种方式。从技术上讲,第三个圆圈可以位于线条的3个像素以内。问题在主题标签的底部附近。我将不胜感激任何帮助或建议,将其朝另一个方向发展。谢谢。

I need to make a small program that draws three circles, a line between the first two, and then determines if the third touches or intersects the line. I have done everything but the last part. I am trying to use the points to determine if the area is 0, which would mean that the third point is, in fact, intersecting the line. Right? Or I could use another way. Technically the third circle can be within 3 pixels of the line. The problem is near the bottom at the hashtag. I would appreciate any help or suggestions that move this in another direction. Thank you.

import turtle

x1, y1 = eval(input("Enter coordinates for the first point x, y: "))
x2, y2 = eval(input("Enter coordinates for the second point x, y: "))
x3, y3 = eval(input("Enter coordinates for the third point x, y: "))

turtle.penup()
turtle.goto(x1, y1)
turtle.pendown()
turtle.circle(3)

turtle.penup()
turtle.goto(x2, y2)
turtle.pendown()
turtle.circle(3)

turtle.penup()
turtle.goto(x3, y3)
turtle.pendown()
turtle.circle(3)

turtle.penup()
turtle.color("red")
turtle.goto(x1, y1)
turtle.pendown()
turtle.goto(x2, y2)

a = (x1, y1)
c = (x3, y3)
#can't multiply sequence by non-int of type 'tuple'

area = (a * c) / 2    

if area == 0:
    print("Hit")
else:
    print("Miss")


推荐答案

我可以吗?圈子彼此的位置没关系吗?

Am I wright? The position of the circles to each other does not matter?

从两个中心点之间的直线上绘制线性函数。 (ax + b = y)
其中a是渐变,b是y交点。

Make a linear function from the line between the two center points. (ax+b=y) Where a is the gradient and b is the y-intersection.

将a旋转90°很容易。求逆并取反。

To rotate a through 90° is easy. Inverse and negate a.

查找第二个线性函数的b。 b’= y-a’* x。
立即将x,y替换为您的3.圆点的坐标。
现在,您有一个线性函数,该线性函数与旧线性函数成矩形,并且第三个圆点是其中的一部分。

Find b of the second linear function. b'=y-a'*x . At once replace the x,y with the coordinates of your 3. circle point. Now you have a linear function which is rectangular to the old one and where the third circle point is part of.

将旧线性函数与新线性函数相交

Intersect the old linear function with the new one.

您会得到很多的。
您需要找出3.圆点与地块点之间的距离,以及是否大于半径。

You'll get the lot point. You need to find out the distance between the 3. circle point and the lot point and whether it is greater than the radius.

您需要那里的函数( JS):

You need there functions (JS):

function makelinear (x1,y1,x2,y2){
         var temp=x2-x1;
         if(temp==0)temp=0.00000000000001;//not clean but fast.
         var a=(y2-y1)/temp,
             b=y1-a*x1;
         return[a,b];
         }
function ninetydeg(a,b,x,y){
         var aout=1/a,
             bout=y+aout*x;
         return [aout,bout];
         }
function lineintersection(a1,b1,a2,b2){
         var temp=a1-a2;
         if(temp==0)temp=0.00000000000001;
         var x=(b2-b1)/temp,
             y=a1*x+b1;
         return[x,y];
         } 
function distance(x1,y1,x2,y2){
         var x=x1-x2,
             y=y1-y2;
         return(Math.sqrt(x*x+y*y));
         }

很抱歉,我在短时间内没有找到其他解决方案。可能有矢量解。

Sorry for to be complicate, I've found no other solution in short time. May be there is a vector solution.

这篇关于龟线相交,坐标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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