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
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
def checkPointInPlane(self, plane: Plane, point: Point): vector = Vector3D(point.getX(), point.getY(), point.getZ()) typeOfPlane = plane.getType() pointInPlane = False if typeOfPlane == "normal": result = vector.subtract(plane.getPositionVector()) answer = result.scalarProduct(plane.getNormalVector()) if answer == 0: pointInPlane = True else: pointInPlane = False elif typeOfPlane == "parameter": dirVec1 = plane.getDirectionVectorOne() dirVec2 = plane.getDirectionVectorTwo() result = vector.subtract(plane.getPositionVector()) arrayOne = np.array([[dirVec1.getX(), dirVec1.getY()], [dirVec2.getX(), dirVec2.getY()]]) arrayTwo = np.array([result.getX(), result.getY()]) solution = np.linalg.solve(arrayOne, arrayTwo) if solution[0] * dirVec1.getZ() + solution[1] * dirVec2.getZ( ) == result.getZ(): pointInPlane = True else: pointInPlane = False elif typeOfPlane == "coordinate": normVec = plane.getNormalVector() if point.getX() * normVec.getX() + point.getY() * normVec.getY( ) + point.getZ() * normVec.getZ() == plane.getScalarParameter(): pointInPlane = True else: pointInPlane = False return pointInPlane
def distancePlanePoint(self, point: Point, plane: Plane): if Solvers.checkPointInPlane(plane, point) == False: if plane.getType() == "coordinate": hess = plane.convertToHessianNormalForm() normVec = hess.getNormalVector() scalarParam = hess.getScalarParameter() distance = normVec.getX() * point.getX() + normVec.getY( ) * point.getY() + normVec.getZ() * point.getZ() - scalarParam else: hess = plane.convertToHessianNormalForm() pointVec = Vector3D(point.getX(), point.getY(), point.getZ()) subtract = pointVec.subtract(hess.getPositionVector()) distance = subtract.scalarProduct(hess.getNormalVector()) distance = abs(distance) else: distance = 0 return distance
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
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
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
import tkinter as tk from tkinter import Canvas, ttk from tkinter.constants import RIDGE from listclass import ObjectLists from vector3Dclass import Vector3D from pointclass import Point from lineclass import Line from planeclass import Plane from nameAssignclass import NameAssign from colorAssignclass import ColorAssign x = Vector3D(3, 4, 5) y = Plane.normalForm(Vector3D(1, 1, 1), Vector3D(2, 2, 2)) z = Plane.parameterForm(Vector3D(3, 4, 5), Vector3D(2, 2, 2), Vector3D(2, 2, 2)) class MainGUI(tk.Frame): width = 1200 height = 700 size = str(width) + "x" + str(height) def __init__(self): self.root = tk.Tk() self.root.title("Vektorplotter") self.root.geometry(self.size) #self.root.resizable(0, 0) self.makeMainframe() self.makeListFrame() self.makeMenuFrame()
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: ") 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].convertToHessianNormalForm())) elif UserInput == "X": running = False else: print("Uberprüfen Sie bitte ihre Eingabe!")