Trajectory curve
-
Hi this is my first post in this Forum, so forgive me for any mistake I do in this post, but I have some code I want to share with you.
I'm not the big ruby-developer and I honestly am not an UI-designer, but I know my math and did some calculations for trajectory curves. I thought here in this Forum are a lot of great developers, who might be interested in my code and have the ability to use it for their plugin, so Sketchup-Users can profit from it.
The trajectory curve is basically a part of a negated parabola and represents the curve of a thrown object, this code draws a trajectory curve by a given distance, a throwangle(degrees), the startheight and the StepCount(number of edges).
Before we get to the code, here some backgroundinfo on the math. I created a graph on https://www.desmos.com/calculator/ceywkjp3nv, which shows you the basic calculations and the resulting curves, you can play around with the variables to see what happens, so you don't have to rewrite the code everytime you change a parameter.
To draw the curve you just have to call this function:
drawTrajectory(distance, angle, startheight, stepCount)
but there are some conitions you should handle before you call the function:
**
- All input-parameters are in [mm]
- the distance must be greater than 0 (distance > 0)
- the throwangle must be greater or equal to 0° and smaller than 90° (0 <= angle < 90)
- the height should be greater than 0 (safe)
It can also be smaller than 0, but then these following conditions have to be true:
trajectory_maxY(start_velocity(distance, degToRad(angle), startheight), degToRad(angle), startheight) >= 0
trajectory_maxX(start_velocity(distance, degToRad(angle), startheight), degToRad(angle)) <= distance
- the stepCount(Number of edges) should be greater than 0 (stepcount > 0), to get an exact drawing it should be greater than 12**
Finally here is the code Ruby code for the trajectory curve
I hope somebody with more programming skills, can use this to build a plugin. I also hope that you will test this code and reply for errors or mistakes, so I can fix them. For any questions on the code, please don't hesitate to ask.
Have fun with it
All the best Marco
-
cheers for posting these scripts...
john
Advertisement