ich bin noch recht am Anfang mit meinen Python-Kenntnissen, daher würde ich mich sehr freuen, falls ihr mir bei dem folgenden Problem weiterhelfen könntet:
Ich habe folgendes Programm geschrieben, bei dem 2 Kurven über einen csv-Import eingelesen werden können.
Jetzt möchte ich im nächsten Schritt die Kurve "Kegelrolle" so lange iterativ verschieben, bis sie an zwei Punkten die Kurve "Innenring" berührt.
Leider bin ich mir nicht sicher wie ich das ganze umsetzen kann, also wie diese schrittweise Verschiebung der Kurve realisiert werden kann, bis eine vorgegebene Bedingung erfüllt ist.
Vielen Dank im Voraus.
Programm aktueller Stand zum Einlesen und plotten der zwei Kurven:
Code: Alles auswählen
import tkinter
import tkinter as tk
import pandas as pd
import numpy as np
import matplotlib as mtpl
import matplotlib.pyplot as plt
import csv
from matplotlib.backends.backend_tkagg import (FigureCanvasTkAgg,
NavigationToolbar2Tk)
from tkinter.filedialog import asksaveasfile
from tkinter.filedialog import askopenfilename
from matplotlib.figure import Figure
from tkinter import ttk
from tkinter import *
class ProfilierungImport:
def __init__(self):
global window
self.window = tk.Tk()
self.window.title("Toleranzanalyse Kontaktgeometrie")
self.window.geometry("400x220")
self.window.resizable(True,True)
def ImportIRCSV():
global x1,y1
x1 = []
y1 = []
with open(askopenfilename(), "r") as csv_file_path_IR:
plots = csv.reader((line.replace(',','.') for line in csv_file_path_IR), csv_file_path_IR, delimiter=";")
for row in plots:
x1.append(float(row[0]))
y1.append(float(row[1]))
def ImportKRCSV():
global x2,y2
x2 = []
y2 = []
with open(askopenfilename(), "r") as csv_file_path_KR:
plots = csv.reader((line.replace(',','.') for line in csv_file_path_KR), csv_file_path_KR, delimiter=";")
for row in plots:
x2.append(float(row[0]))
y2.append(float(row[1]))
def RotIR():
global x1_versch, y1_versch
alpha1 = -5.6767128
valueX = [10, 36]
x1_array = np.array(x1)
y1_array = np.array(y1)
x1_kor = x1_array - x1[0]
y1_kor = y1_array - y1[0]
x1_versch = x1_kor * np.cos(np.radians(alpha1)) - y1_kor * np.sin(np.radians(alpha1))
y1_versch = x1_kor * np.sin(np.radians(alpha1)) + y1_kor * np.cos(np.radians(alpha1))
print(x1_kor, y1_kor)
print(x1_versch, y1_versch)
alpha2 = -4.088817418
x2_array = np.array(x2)
y2_array = np.array(y2)
x2_kor = x2_array - x2[0]
y2_kor = y2_array - y2[0]
x2_versch = (x2_kor * np.cos(np.radians(alpha2)) - y2_kor * np.sin(np.radians(alpha2)))
y2_versch = (x2_kor * np.sin(np.radians(alpha2)) + y2_kor * np.cos(np.radians(alpha2)))
x1list = x1_versch.tolist()
y1list = y1_versch.tolist()
x2list = x2_versch.tolist()
y2list = y2_versch.tolist()
x2res = [x + float(VerschX.get()) for x in x2list]
y2res = [x + float(VerschY.get()) for x in y2list]
#plt.plot(x1_versch, y1_versch)
fig = plt.figure()
ax = fig.add_subplot(111)
ax.plot(x1list, y1list)
ax.plot(x2res, y2res)
plt.xlabel('Messpunkt')
plt.ylabel('Profilierung [mm]')
plt.title('Laufbahnprofilierung')
plt.show()
fig, axs = plt.subplots(2, 3)
axs[0, 0].plot(x1list, y1list)
axs[0, 0].set_title('Innenring')
axs[0, 0].grid(linestyle='dotted', color='grey')
axs[0, 1].plot(x2res, y2res, 'tab:orange')
axs[0, 1].set_title('Kegelrolle')
axs[0, 1].grid(linestyle='dotted', color='grey')
axs[1, 0].plot(x1list, y1list, x2res, y2res, 'tab:orange')
axs[1, 0].set_title('Kontaktgeometrie')
axs[1, 0].grid(linestyle='dotted', color='grey')
axs[1, 1].plot(x1list, y1list, x2res, y2res, 'tab:orange')
axs[1, 1].set_title('Profilierung')
axs[1, 1].set_xlim([12.5, 34.5])
axs[1, 1].set_ylim([-1.48, -1.42])
axs[1, 1].grid(linestyle='dotted', color='grey')
axs[0, 2].plot(x1list, y1list, x2res, y2res, 'tab:orange')
axs[0, 2].set_title('Kontaktgeometrie')
axs[0, 2].set_xlim([9.52, 9.56])
axs[0, 2].set_ylim([-2, 2])
axs[0, 2].grid(linestyle='dotted', color='grey')
axs[1, 2].plot(x1list, y1list, x2res, y2res, 'tab:orange')
axs[1, 2].set_title('Kontaktgeometrie')
axs[1, 2].set_xlim([36, 39])
axs[1, 2].set_ylim([-2, 2])
axs[1, 2].grid(linestyle='dotted', color='grey')
new_window = tk.Tk()
new_window.title("Toleranzanalyse Profilierung")
new_window.geometry("1200x900")
new_window.resizable(True,True)
canvas = FigureCanvasTkAgg(fig, new_window)
canvas.draw()
canvas.get_tk_widget().pack(side=tkinter.TOP, fill=tkinter.BOTH, expand=1)
toolbar = NavigationToolbar2Tk(canvas, new_window)
toolbar.update()
canvas.get_tk_widget().pack(side=tkinter.TOP, fill=tkinter.BOTH, expand=1)
ImportIR = tk.Button(self.window, text="Import IR", width=12, bg="#CCCCCC", command=ImportIRCSV)
ImportIR.grid(row=0, column=0, padx=30, pady=2, sticky="n")
ImportKR = tk.Button(self.window, text="Import KR", width=12, bg="#CCCCCC", command=ImportKRCSV)
ImportKR.grid(row=1, column=0, padx=30, pady=2, sticky="n")
Plot = tk.Button(self.window, text='Plot', width=12, bg='#CCCCCC', command=RotIR)
Plot.grid(row=0, column=1, padx=30, pady=2, sticky='n')
Save = tk.Button(self.window, text='Speichern', width=12, bg='#CCCCCC')
Save.grid(row=4, column=0, padx=30, pady=2, sticky='n')
Load = tk.Button(self.window, text='laden...', width=12, bg='#CCCCCC')
Load.grid(row=5, column=0, padx=30, pady=2, sticky='n')
VerschiebungX = Label(self.window, text="Verschiebung x [mm]", width=15)
VerschiebungX.grid(row=2, column=0, sticky="n", padx=8)
VerschiebungY = Label(self.window, text="Verschiebung y [mm]", width=15)
VerschiebungY.grid(row=3, column=0, sticky="n", padx=8)
VerschX = StringVar(value="38.423")
Entry(self.window, textvariable = VerschX,
justify = RIGHT, width="10").grid(row=2, column=1, sticky="n", padx=8)
VerschY = StringVar(value="3.39")
Entry(self.window, textvariable = VerschY,
justify = RIGHT, width="10").grid(row=3, column=1, sticky="n", padx=8)
self.window.mainloop()
ProfilierungImport()