cone_calc.html
001|
002| from sys import argv
003| from os import path
004| from math import sqrt, pi, sin,cos,radians,degrees, acos
005| from goodies import intervals
006| from files import linefile
007|
008| BasePath = r'C:\CJS\prj\Python\blog\proj'
009|
010| Radius = 1.0
011|
012|
013| def cone_distance_calculation (n=12, fname='cone-calc.out', fpath=BasePath):
014|
015| fn = path.join(fpath,fname) if fpath else fname
016| fo = linefile(fn)
017|
018| for ix in range(n+1):
019| angle = (pi/2.0) * (ix/n)
020| px = cos(angle)
021| py = sin(angle)
022| pt = (py * py) / px
023| xlen = Radius * (px + pt)
024|
025| s = f'{ix:3d}: {degrees(angle):6.3f} {px:6.3f} {py:6.3f} {pt:6.3f} {xlen:6.3f}'
026| print(s)
027| fo.data.append(s)
028|
029| print()
030| fo.data.append('')
031| fo.save()
032|
033| return fo.data
034|
035|
036| def law_of_cosines (a, b, c):
037| alpha = degrees(acos((-pow(a,2)+pow(b,2)+pow(c,2)) / (2*b*c)))
038| beta = degrees(acos((+pow(a,2)-pow(b,2)+pow(c,2)) / (2*a*c)))
039| gamma = degrees(acos((+pow(a,2)+pow(b,2)-pow(c,2)) / (2*a*b)))
040| return (alpha, beta, gamma)
041|
042|
043| def test_law_of_cosines ():
044| r = 1.7
045|
046| for d in intervals(r+0.1, (3*r), 0.1):
047| a,b,c = law_of_cosines(r, d, sqrt(pow(d,2)-pow(r,2)))
048| x = r * cos(radians(c))
049| y = r * sin(radians(c))
050| print(f'{d:.1f}: {a:.3f} {b:.3f} {c:.3f} (={a+b+c:.3f}) [{x:.2f}, {y:.2f}]')
051| print()
052|
053|
054| d = 25
055| return law_of_cosines(22.92, r, d)
056|
057|
058|
059| def main (*args):
060| rv = ()
061|
062| rv = test_law_of_cosines()
063| return rv
064|
065| if __name__ == '__main__':
066| print(argv[0])
067| print()
068| rv = main(*argv[1:])
069| print()
070|
071| '''eof'''
072|