#! /usr/bin/python3 -t # _*_ coding: iso-8859-1 _*_ # Last edited on 2024-07-27 08:29:10 by stolfi PROG_NAME = "involute_test" PROG_DESC = "Tests the Python {involute} module" PROG_VERS = "1.0" PROG_COPYRIGHT = "Copyright © 2009 State University of Campinas" PROG_INFO = "!!! PROG_INFO to be written" import sys; import os; import copy; import involute; import rn; import math; from math import sqrt, sin, cos, floor, ceil, inf, nan, pi def test_points(): sys.stderr.write("------------------------------------------------------------\n"); sys.stderr.write("Testing plot:\n"); pCirc = 10 # Circular pitch (mm). theta = 20*pi/180 # Pressure angle (radians). np = 50 # Number of points. N = 27 # Number of teeth. dPitch = involute.dPitch_from_pCirc(N, pCirc) dBase = involute.dBase_from_dPitch(dPitch, theta) dd = dPitch - dBase # Tooth half-height. dMin1 = dBase dMax1 = dBase + 12*dd v1 = involute.points(dBase, dMin1, dMax1, np) write_points("v1", v1) dMin2 = dBase + 0.2*dd dMax2 = dBase + 1.8*dd v2 = involute.points(dBase, dMin2, dMax2, np) write_points("v2", v2) vb = circle_points(dBase, dBase, 3*np) write_points("vb", vb) return def test_meshing(): sys.stderr.write("------------------------------------------------------------\n"); sys.stderr.write("Testing meshing:\n"); pCirc = 10 # Circular pitch (mm). theta = 20*pi/180 # Pressure angle (radians) np = 50 # Number of points. N1 = 8 dPitch1 = involute.dPitch_from_pCirc(N1, pCirc) dBase1 = involute.dBase_from_dPitch(dPitch1, theta) dTip1 = dBase1 + 12*(dPitch1 - dBase1) vi1 = involute.points(dBase1, dBase1, dTip1, np) vb1 = \ circle_points(dBase1, dBase1, 3*np) + \ circle_points(dPitch1, dBase1, 3*np) N2 = 9 dPitch2 = involute.dPitch_from_pCirc(N2, pCirc) dBase2 = involute.dBase_from_dPitch(dPitch2, theta) dTip2 = dBase2 + 12*(dPitch2 - dBase2) vi2 = involute.points(dBase2, dBase2, dTip2, np) vb2 = \ circle_points(dBase2, dBase2, 3*np) + \ circle_points(dPitch2, dBase2, 3*np) dCtr12 = dPitch1 + dPitch2 alpha1 = involute.alpha_at_given_d(dPitch1, dBase1) omega1 = involute.omega_from_alpha(alpha1) shift_rot_shift(vi1, dBase1/2, -omega1, -dPitch1/2) write_points("vi1", vi1) shift_rot_shift(vb1, dBase1/2, -omega1, -dPitch1/2) write_points("vb1", vb1) alpha2 = involute.alpha_at_given_d(dPitch2, dBase2) omega2 = involute.omega_from_alpha(alpha1) shift_rot_shift(vi2, dBase2/2, pi-omega2, +dPitch2/2) write_points("vi2", vi2) shift_rot_shift(vb2, dBase2/2, pi-omega2, +dPitch2/2) write_points("vb2", vb2) return def circle_points(d, dBase, n): # Returns a list of {n} points on a circle with diameter {d}, # centered at the pount { (-dBase/2, 0) } rad = d/2 ctrx = -dBase/2 v = [] for k in range(n + 1): a = 2*pi*k/n x = rad*cos(a) + ctrx y = rad*sin(a) v.append((x,y)) return v def shift_rot_shift(v, dx0, a, dx1): # Shifts the points {v} by {dx0} in {X}, # rotates them by {a} radians, then shifts them by {dx1}. ca = cos(a) sa = sin(a) for k in range(len(v)): vk = v[k] x1 = vk[0] + dx0; y1 = vk[1] x2 = + ca*x1 - sa*y1 y2 = + sa*x1 + ca*y1 v[k] = (x2 + dx1, y2) return def write_points(name, v): wrp = open(f"out/{name}.txt", "w") for k in range(len(v)): vk = v[k] wrp.write("%4d %12.8f %12.8f\n" % (k, vk[0], vk[1])) wrp.close() def data_error(msg) : "Prints the error message {msg} about the current input line, and aborts." sys.stderr.write("%s:%d: %s\n" % (in_file_name, in_line_number, msg)); sys.exit(1) def arg_error(msg): "Prints the error message {msg} about the command line arguments, and aborts." sys.stderr.write("%s\n" % msg); sys.stderr.write("usage: %s\n" % PROG_HELP); sys.exit(1) test_points() test_meshing()