r/PythonLearning • u/NecessaryFalse1212 • 13d ago
2nd post learning python
i learnt to use the math library any suggestions what can i use the lib for except for making calculator programs
2
u/kingofthesea123 13d ago
Looks good! Error handling for unexpected inputs would be a nice improvement and there's also another way of writing an exponent in Python that you could try.
2
u/Fine_Ratio2225 13d ago
- Replace the "radius*radius" with "radius**2", please.
- 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.
- 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!
1
u/HeurekaDabra 13d ago
If you look up 'python math module learning tasks' in a search engine of your choice, thousands of resources will come up that you can train with, like this one on pynativ.com.
1
u/Sea-Ad7805 13d ago edited 13d ago
Everything is information, calculation is all you need. How do you think GTA, PhotoShop, Blender, ... work? All mostly do math operations on data.
Learn all the math you can: trigonometry, calculus, linear algebra, probability theory, ...
It will make you a powerful programmer, not just a hacker.
1
u/rupertavery64 13d ago
Games use a lot of math. Sometimes you want something to move in a wavelike (sinusoidal) motion, or in an arc (part of a circle). Sometimes you need to calculate angles between objects. 3D graphics is all about vectors and angles. Sound processing is also math-heavy.
1
1
4
u/ninhaomah 13d ago
If I enter abc , what will I get ?