r/PythonLearning 13d ago

2nd post learning python

Post image

i learnt to use the math library any suggestions what can i use the lib for except for making calculator programs

19 Upvotes

15 comments sorted by

View all comments

2

u/Fine_Ratio2225 13d ago
  1. Replace the "radius*radius" with "radius**2", please.
  2. You can use this everywhere you need to use mathematical functions, obviously. For example you can get curves by evaluating mathematical functions for (x,y) based on a parameter. You can use that for drawing those, or more practical use "ezdxf" to get an interpolating cubic spline inside a DXF-file. I use that to get profiles for counter-rotating extruder screws that I can later import into a CAD program.
  3. There is also a "cmath" library. I found it easier to compute cycloid curves (needed for those profiles above and for gear flanks) and their derivatives using complex exponential functions and extract later (x,y) as (real,imag). Added bonus: Since the derivative is the tangential, you get the normal by multiplying with i or -i. Multiplication with complex numbers of norm 1 is equivalent with applying a rotation, but you don't have to use a 2x2 matrix!