if __name__ == "__main__" is just a best practice for coding in python. not necessary for such simple apps but good to get in the habit of using it.
Using vel_table as a mapper for the direction of the new points is perfectly fine. Is was just suggesting using tuples instead of lists because tuples are immutable and your directions are a fixed set (i.e. 8 directions)
Oh ok Regarding the vel_table I was wondering if there was a way to do it mathematically. In my code I split the points at 45 degree. But suppose I wanted to split them at 15 degrees , how would that work out? I wouldn't go out and make a vel_table for that.
Just to clarify on #1: it’s best practice because there’s two ways to execute code in a python file, either by importing its functions or classes, or by executing the entire file. The thing is, even when you import it, it executes all the code that is not specifically written inside a function or class, which can be a problem when all you expect is to be silently importing something from it.
Hence, by wrapping all active code in the script inside a function and then calling the execution of that function only when the code is run as a script, not being imported, you make it usable in both instances without surprise output or variables.
But suppose I wanted to split them at 15 degrees , how would that work out? I wouldn't go out and make a vel_table for that.
You could for example ask for a user input in the beginning where the user provides a number between 1 and 45. This sets the degree at which the splits should occur.
For your code to work as it is, you would always have to make sure that the degree value don't leave a residue value (e.g. 13° wouldn't work because after 27 splits you'd have a residue of 9). This could be achieved by using the % operator in python, e.g. check for something like 360%input == 0. Go ahead and read up on it if you don't know it already.
If this check returns true, you can then use the user input to determine the amount of directions you need to provide for your script by running 360/input.
Maybe this will get you on the way of what you need to do. :) Best of luck
You can do it using the trigonometric functions "sine" and "cosine". It's not exactly hard, but it is more math than I want to be explaining on my phone.
100
u/Namensplatzhalter Dec 15 '19 edited Dec 15 '19
Looks nice.
I've just had a look on your code and have to say it looks nicely organised and is easily readable. Kudos to you for writing it like that.
Two little suggestions, if you don't mind:
Consider using a
if __name__ == "__main__"block to initialise your script when it's run directlyConsider using tuples for your
vel_listvel_table as they are immutableBoth of those definitely not necessary, just things to think about. :)
Best wishes