Exemple #1
0
    def schnittgerade(self, plane1: Plane, plane2: Plane):
        """Calculates and Returns the schnittgerade of two Planes.
           Returns a Line instance."""
        pla1 = plane1.convertToHessianNormalForm()
        pla2 = plane2.convertToHessianNormalForm()

        normvec1 = pla1.normVec
        normvec2 = pla2.normVec

        posnum1 = pla1.posVec.scalarProduct(normvec1)
        posnum2 = pla2.posVec.scalarProduct(normvec2)

        schnittgerade = not Solvers.checkLinearAbhaengig(
            normvec1, normvec2)  # Testing if the Planes are not Parallel

        if schnittgerade:
            dirVec = normvec1.vectorProduct(normvec2)
            posVecScalar1 = ((posnum1 * normvec2.square()) -
                             (posnum2 * normvec1.scalarProduct(normvec2))) / (
                                 (normvec1.square() * normvec2.square()) -
                                 normvec1.scalarProduct(normvec2)**2)
            posVecScalar2 = ((posnum2 * normvec1.square()) -
                             (posnum1 * normvec1.scalarProduct(normvec2))) / (
                                 (normvec1.square() * normvec2.square()) -
                                 normvec1.scalarProduct(normvec2)**2)
            normvec1 = normvec1.scalarMultiplication(posVecScalar1)
            normvec2 = normvec2.scalarMultiplication(posVecScalar2)
            posVec = normvec1.add(normvec2)
            schnittgerade = Line(posVec,
                                 dirVec,
                                 name=("Schnittgerade von " + pla1.name +
                                       " und " + pla2.name))
        return schnittgerade
Exemple #2
0
 def distancePointLine(self, point: Point, line: Line):
     helpPlane = Plane.normalForm(
         Vector3D(point.getX(), point.getY(), point.getZ()),
         line.getDirectionVector())
     pointSchnitt = Solvers.solveForPointPlane(line, helpPlane)
     schnittPoint = Point(pointSchnitt.getX(), pointSchnitt.getY(),
                          pointSchnitt.getZ())
     distance = Solvers.distancePointPoint(schnittPoint, point)
     return distance
Exemple #3
0
 def distanceLinePlane(self, line: Line, plane: Plane):
     if plane.getType() == "normal" or plane.getType() == "coordinate":
         normVec = plane.getNormalVector()
         if normVec.scalarProduct(line.getDirectionVector()) == 0:
             distance = Solvers.distancePlanePoint(line.getPositionVector(),
                                                   plane)
         else:
             distance = 0
         return distance
     else:
         normVec = plane.getDirectionVectorOne().vectorProduct(
             plane.getDirectionVectorTwo())
         if normVec.scalarProduct(line.getDirectionVector()) == 0:
             distance = Solvers.distancePlanePoint(line.getPositionVector(),
                                                   plane)
         else:
             distance = 0
         return distance
Exemple #4
0
    def schnittpunkt(self, line1: Line, line2: Line):
        """Returns the Schnittpunkt between two Lines.
           Uses Solvers.solveForSchnittstelle.
           Returns a Point instance."""

        posVec1 = line1.getPositionVector()
        posVec2 = line2.getPositionVector()
        dirVec1 = line1.getDirectionVector()
        dirVec2 = line2.getDirectionVector()
        schnittstelle = self.solveForSchnittstelle(line1, line2)

        ValOne = posVec1.add(dirVec1.scalarMultiplication(schnittstelle[0]))
        ValTwo = posVec2.add(dirVec2.scalarMultiplication(schnittstelle[0]))
        if ValOne.getX() == ValTwo.getX() and ValOne.getY() == ValTwo.getY(
        ) and ValOne.getZ() == ValTwo.getZ():
            schnittpunkt = ValOne
        else:
            schnittpunkt = None
        return schnittpunkt
Exemple #5
0
def main():
    pygame.init()
    screen = pygame.display.set_mode((640,480))
    pygame.display.set_caption("Animated Line")
    line = Line(screen)
    clock = pygame.time.Clock()
    while 1:
        clock.tick(30)
        screen.fill((50, 50, 100))
        line.update()
        line.draw()
        pygame.display.flip()
        for event in pygame.event.get():
            if event.type == QUIT:
                pygame.quit()
                return
            elif event.type == KEYDOWN and event.key == K_ESCAPE:
                pygame.quit()
                return
Exemple #6
0
 def solveForPointPlane(self, line: Line, plane: Plane):
     if plane.getType() == "normal":
         normVec = plane.getNormalVector()
         posVecP = plane.getPositionVector()
         scalarParam = posVecP.scalarProduct(normVec)
         posVec = line.getPositionVector()
         dirVec = line.getDirectionVector()
         xValNoVar = normVec.getX() * posVec.getX()
         yValNoVar = normVec.getY() * posVec.getY()
         zValNoVar = normVec.getZ() * posVec.getZ()
         xValVar = normVec.getX() * dirVec.getX()
         yValVar = normVec.getY() * dirVec.getY()
         zValVar = normVec.getZ() * dirVec.getZ()
         ValVar = xValVar + yValVar + zValVar
         ValNoVar = scalarParam - xValNoVar - yValNoVar - zValNoVar
         Var = ValNoVar / ValVar
         SchnittPoint = Point(posVec.getX() + Var * dirVec.getX(),
                              posVec.getY() + Var * dirVec.getY(),
                              posVec.getZ() + Var * dirVec.getZ())
         return SchnittPoint
     elif plane.getType() == "coordinate":
         normVec = plane.getNormalVector()
         scalarParam = plane.getScalarParameter()
         posVec = line.getPositionVector()
         dirVec = line.getDirectionVector()
         xValNoVar = normVec.getX() * posVec.getX()
         yValNoVar = normVec.getY() * posVec.getY()
         zValNoVar = normVec.getZ() * posVec.getZ()
         xValVar = normVec.getX() * dirVec.getX()
         yValVar = normVec.getY() * dirVec.getY()
         zValVar = normVec.getZ() * dirVec.getZ()
         ValVar = xValVar + yValVar + zValVar
         ValNoVar = scalarParam - xValNoVar - yValNoVar - zValNoVar
         Var = ValNoVar / ValVar
         SchnittPoint = Point(posVec.getX() + Var * dirVec.getX(),
                              posVec.getY() + Var * dirVec.getY(),
                              posVec.getZ() + Var * dirVec.getZ())
         return SchnittPoint
     elif plane.getType() == "parameter":
         normVec = plane.getDirectionVectorOne().vectorProduct(
             plane.getDirectionVectorTwo())
         posVecP = plane.getPositionVector()
         scalarParam = posVecP.scalarProduct(normVec)
         posVec = line.getPositionVector()
         dirVec = line.getDirectionVector()
         xValNoVar = normVec.getX() * posVec.getX()
         yValNoVar = normVec.getY() * posVec.getY()
         zValNoVar = normVec.getZ() * posVec.getZ()
         xValVar = normVec.getX() * dirVec.getX()
         yValVar = normVec.getY() * dirVec.getY()
         zValVar = normVec.getZ() * dirVec.getZ()
         ValVar = xValVar + yValVar + zValVar
         ValNoVar = scalarParam - xValNoVar - yValNoVar - zValNoVar
         Var = ValNoVar / ValVar
         SchnittPoint = Point(posVec.getX() + Var * dirVec.getX(),
                              posVec.getY() + Var * dirVec.getY(),
                              posVec.getZ() + Var * dirVec.getZ())
         return SchnittPoint
Exemple #7
0
 def distanceLineLine(self, line1: Line, line2: Line):
     if Solvers.checkLinearAbhaengig(line1.getDirectionVector(),
                                     line2.getDirectionVector()) == True:
         if Solvers.checkPointInLine(line1,
                                     line2.getPositionVector()) == True:
             print("Identisch")
         else:
             distance = Solvers.distancePointLine(line2.getPositionVector(),
                                                  line1)
     elif Solvers.schnittpunkt(line1, line2) is not None:
         distance = 0
     else:
         normVec = line1.getDirectionVector().vectorProduct(
             line2.getDirectionVector())
         scalarParam = normVec.scalarProduct(line1.getPositionVector())
         helpPlane = Plane.coordinateForm(normVec, scalarParam)
         distance = Solvers.distancePlanePoint(line2.getPositionVector(),
                                               helpPlane)
     return distance
Exemple #8
0
def main():
    pygame.init()
    screen = pygame.display.set_mode((640,480))
    pygame.display.set_caption("Animated Line")
    lines = [Line(screen) for x in range(20)]
    clock = pygame.time.Clock()
    while 1:
        clock.tick(30)
        screen.fill((50, 50, 100))
        for line in lines:
            line.update()
            line.draw()
        pygame.display.flip()
        for event in pygame.event.get():
            if event.type == QUIT:
                pygame.quit()
                return
            elif event.type == KEYDOWN and event.key == K_ESCAPE:
                pygame.quit()
                return
Exemple #9
0
     Vec2 = Vector3D(input("x = "),input("y = "),input("z = "),input("Name = "))
     print("Ergebnis: " + str(Vec1.scalarProduct(Vec2)))
 elif UserInput == "VecMultVecCro":
     Vec1 = Vector3D(input("x = "),input("y = "),input("z = "),input("Name = "))
     Vec2 = Vector3D(input("x = "),input("y = "),input("z = "),input("Name = "))
     print("Ergebnis: " + str(Vec1.vectorProduct(Vec2)))
 elif UserInput == "NewPoi":
     PoiList.append(Point(input("x = "),input("y = "),input("z = "),input("Name = ")))
     print(str(PoiList[-1]))
 elif UserInput == "NewLin":
     print("Position Vector: ")
     Vec1 = Vector3D(input("x = "),input("y = "),input("z = "),input("Name = "))
     print("Direction Vector: ")
     Vec2 = Vector3D(input("x = "),input("y = "),input("z = "),input("Name = "))
     name = input("Name: ")
     LinList.append(Line(Vec1, Vec2, name, (0, 0, 0)))
     print(str(LinList[-1]))
 elif UserInput == "NewPla":
     print("Position Vector: ")
     Vec1 = Vector3D(input("x = "),input("y = "),input("z = "),input("Name = "))
     print("Direction Vector One: ")
     Vec2 = Vector3D(input("x = "),input("y = "),input("z = "),input("Name = "))
     print("Direction Vector Two: ")
     Vec3 = Vector3D(input("x = "),input("y = "),input("z = "),input("Name = "))
     name = input("Name: ")
     PlaList.append(Plane.parameterForm(Vec1, Vec2, Vec3, name, (0, 0, 0)))
     print(str(PlaList[-1]))
 elif UserInput == "ConvertPlaToHess":
     print("Position Vector: ")
     Vec1 = Vector3D(input("x = "),input("y = "),input("z = "),input("Name = "))
     print("Direction Vector One: ")