检查三角形的顶点是否共线

问题描述 投票:0回答:1

事情变得有点复杂了。

不幸的是,我们的教授使用他自己的图书馆。也许有人仍然可以帮助我。它通常与几何和齐次坐标有关。任务是构造一个外接圆,该外接圆穿过读取的文件中的所有顶点。为此,我计算了中心垂线并确定了交点。外接圆的绘制对我来说有点不清楚,所以我首先将其绘制为 31.5。现在的任务是查看这些点是否共线。如果有人想测试它,我会在这里上传供阅读的文件和库。

我卡住的地方是 #check 三角形的三个顶点是否共线的线

有什么不清楚的地方请随时询问。

最诚挚的问候 泽巴特

import sys
import time
import math
import numpy as np
from enum import Enum
from libcfcg import cf

pointsV = [] # python representation of point vectors
cfPoints = [] # internal 2D representation with x and y
pointVectorsV = [] # internal pointVector representation with x, y, and w

def myEqualZero(value):  # if you expect 0 it's mostly a very small number but not 0!!!
    return abs(value) < 0.001

def mySign(value):  # difference to NumPy:  mySign(0)=1    !!!
    if value < 0:
        return -1
    return 1

def readPoints():
    dataV = cf.readDatFilePointVector("geometry_files/UMKREIS1.DAT")

    for i in range(0, dataV.size()):
        pV = dataV.get(i)
        pointsV.append([pV.getX(), pV.getY(), pV.getW()])

    for pV in range(0, len(pointsV)):
        if pointsV[pV][2] != 1:
            raise ValueError;
        cfPoints.append(cf.Point(pointsV[pV][0], pointsV[pV][1]))  # drawable points
        pointVectorsV.append(cf.PointVector(pointsV[pV][0], pointsV[pV][1])) # list of Point-Vectors

readPoints()

# part 1, create coordinatesystem & draw all points/lines
window = cf.WindowCoordinateSystem(600, cf.Interval(-10, 270), cf.Interval(-10, 270), "Coordinatesystem")
window.setWindowDisplayScale(1.0)
window.drawAxis(cf.Color.BLACK, 10, 10)

# Read points of the triangle
for pV in pointsV:
    print("Drawing point: ", pV)
    sys.stdout.flush() # force output
    time.sleep(0.1) # wait for console; increase if necessary
    window.drawPoint(cf.Point(pV[0], pV[1])) # default color is black
# Draw points of the triangle
for i in range(0, len(cfPoints)):
    p0 = cfPoints[i]
    p1 = cfPoints[(i+1) % len(cfPoints)] 
    window.drawLine(p0, p1)

window.show() # no display of drawings without this line!!!


Mittelpunkte = []
Punkte = []

#Determine and draw perpendiculars
print("Taste drücken, um Mittelsenkrechten einzuzeichnen")
sys.stdout.flush() # force output
time.sleep(0.1) # wait for console; increase if necessary
window.waitKey()
for pV in range(0,2):
    
    #Calculate the center point from two points
    MPV1 = pointVectorsV[pV].add(pointVectorsV[pV+1])
    MPV1.normalize()
    Mittelpunkte.append(MPV1)
    MP1 = cf.Point(MPV1)
    window.drawPoint(MP1)
    window.show()
    
    #Direction vector for G, PointV1 - MPV1
    RMPV1 = pointVectorsV[pV+1].sub(MPV1)
    
    #Calculate normal direction vector from direction vector
    NMPV1 = RMPV1.clone()
    NEWX = RMPV1.getY()*(-1)
    NEWY = RMPV1.getX()
    NMPV1.setX(NEWX)
    NMPV1.setY(NEWY)
    
    # Calculate X1 from H with r=3
    X1 = MPV1.add(NMPV1*3)
    Punkte.append(X1)
    XP1 = cf.Point(X1)
    window.drawPoint(XP1, cf.Color.BLUE)
    window.show()
    
    # Draw perpendiculars through X1 and X2
    window.drawLine(MP1, XP1, cf.Color.BLUE, cf.Window2D.LineType_DEFAULT, 1)
    window.show()
    

#Calculate and draw the intersection of the perpendiculars
print("Taste drücken, um den Schnittpunkt der Mittelsenkrechten einzuzeichnen")
sys.stdout.flush() # force output
time.sleep(0.1) # wait for console; increase if necessary
window.waitKey()

N1 = Mittelpunkte[0].crossProduct(Punkte[0])
N2 = Mittelpunkte[1].crossProduct(Punkte[1])
N1.normalize()
N2.normalize()
S = N1.crossProduct(N2)
S.normalize()
print("Test", S.getX(), S.getY(), S.getW())
SP1 = cf.Point(S)
window.drawPoint(SP1, cf.Color.RED)
window.show()


#Draw a circle around the center of the vertical and at the three corner points
print("Taste drücken, um den den Kreis der 3 Punktvektoren einzuzeichnen")
sys.stdout.flush() # force output
time.sleep(0.1) # wait for console; increase if necessary
window.waitKey()

window.drawCircle(SP1, 31.5, cf.Color.GREEN)
window.show()



#check whether the three vertices of the triangle are collinear
print("Taste drücken, um zu überprüfen ob die Punkte Kollinear sind")
sys.stdout.flush() # force output
time.sleep(0.1) # wait for console; increase if necessary
window.waitKey()



    
# end
print("Press any key to finish")
sys.stdout.flush() # force output
time.sleep(0.1) # wait for console; increase if necessary
window.waitKey()

window = None
geometry computational-geometry
1个回答
0
投票

如果

A,B,C
AB
向量的向量乘积为零,则
AC
三个点位于同一条线上:

(C.X-A.X)*(B.Y-A.Y)-(C.Y-A.Y)*(B.X-A.X) == 0
© www.soinside.com 2019 - 2024. All rights reserved.