Jump to content

Physics script


erifash
 Share

Recommended Posts

Any first-year in physics should learn this:

; Variables
;==============================
$n_orig_velocity = 40
$n_angle = 35

; Constants
;==============================
$n_acceleration_y = -9.8
$n_acceleration_x = 0

; Calculations
;==============================
$n_velocity_x = $n_orig_velocity * Cos(_Radian($n_angle))
$n_velocity_y = $n_orig_velocity * Sin(_Radian($n_angle))
$n_half_time = ( 0 - $n_velocity_y ) / $n_acceleration_y                            ;Return: Time to halfway point in trajectory
$n_displacement_y = ( $n_velocity_y * $n_half_time ) + ( 0.5 * $n_acceleration_y * ( $n_half_time * $n_half_time ) );Return: Vertical displacement
$n_total_time = 2 * $n_half_time                                        ;Return: Total time in trajectory
$n_displacement_x = $n_velocity_x * $n_total_time                                ;Return: Horizontal displacement

; Return
;==============================
$s_ret = "Velocity: " & $n_orig_velocity & " meters per second" & @CRLF & "Angle: " & $n_angle & " degrees" & @CRLF & "Horizontal Velocity: " & $n_velocity_x & " meters per second" & @CRLF & "Vertical velocity: " & $n_velocity_y & " meters per second" & @CRLF & "Time to halfway point in trajectory: " & $n_half_time & " seconds" & @CRLF & "Total time in trajectory: " & $n_total_time & " seconds" & @CRLF & "Horizontal displacement: " & $n_displacement_x & " meters" & @CRLF & "Vertical displacement: " & $n_displacement_y & " meters"
ClipPut($s_ret)
Run("notepad.exe", @SystemDir, @SW_MAXIMIZE)
Do
  Sleep(100)
Until WinActive("Untitled - Notepad", "")
Send("^v")

Func _Radian($nDegrees)
        If not Number($nDegrees) Then
        SetError(1)
        Return ""
    EndIf
    Return $nDegrees / 57.2957795130823
EndFunc

Just to make things easier! Also, I will be submitting this _Radian() function to math.au3 as AutoIt currently has no function to convert degrees into radians.

EDIT: Angle is measured in degrees and velocity is measured in meters per second.

Edited by erifash
Link to comment
Share on other sites

Anyone find this useful? I know we aren't in school right now (which is very good) but AutoIt still involves math, and that is what this script does.

Maybe I wasn't clear the first time (okay I wasn't) but this script figures out how high an object will fly, how far away it will land, and how much time passes based on how hard it is thrown and at what angle. It simulates this on a flat plane with no wind resistance under earth's gravity. :)

Any questions/comments? :evil:

Link to comment
Share on other sites

Well the thing is, physics is definately the last thing we're thinking about when we're programming in it. If we really did need this info, then we would probably look online or in a textbook - atleast I would.

Link to comment
Share on other sites

Well the thing is, physics is definately the last thing we're thinking about when we're programming in it.

<{POST_SNAPBACK}>

What??? :evil: I thought you were supposed to think about something when you are programming it (well, at least I do).

On the topic of looking at an online help manual, that's what I did when I programmed this script. Now I gave you this script so you wouldn't have to look online or in a manual! Isn't that just the basic idea of programming? Making things simpiler? Or am I just abnormal and all of you are normal? :)

Link to comment
Share on other sites

I tried to take physics in highschool, waaaaay back in grade 11 (wow.. 6 years ago), but I was a horrible student and the teacher didn't make things much easier. I believe for the month that I stayed in that class we had like five days that weren't taking down notes from the overhead projector. Four of those days we did tests, and one was an experiment dealing with gravity, which lasted a whole of about 5 seconds, then it was back to notes. I just wasn't built with the patience to handle writing down endless pages of numbers and formulas without being able to put practical use to them.

ANYWAY, in more recent years I've delved slightly into the more physical aspect of programming (trying to make objects appear to fall, bounce, gravitational effects in general) and sort of regret my never being to follow through that class. I'm sure for the ones of us here who need such a function, yours will come in quite handy. It's just that at the moment.. none of us need it I guess. :)

Just my $0.02 (more like $2.00 actually, jeeze I talk too much).

Link to comment
Share on other sites

Jeez, if only I had this when I was in precalc, too many physics equations in that annoying book... :)

That's actually the first script I've seen that actually uses AutoIts math functions (sin, cos, etc)

Writing AutoIt scripts since

_DateAdd("d", -2, _NowCalcDate())
Link to comment
Share on other sites

Hey I made one that used Sin and Cos. It made the mouse cursor spin around in a circle. :evil:

<{POST_SNAPBACK}>

Ahhhh, MouseFlush I believe? Thank you for the great comments!

@layer: I am also going into 9th grade and I really like math. Algebra 1 gave me a taste for this and I always wanted to know how they got the a b and c in ax^2+bx+c to translate into angle, speed, and vertical displacement (very confusing, and I still don't get it). Funny thing is they gave us this example of a discus thrower with the equation for the parabola the discus makes, but they never showed us how to get a b and c in the equation for throwing a given object! :)

Link to comment
Share on other sites

You may want to create scripts that give you angles and sides of triangles using various inputted variables. It helps a lot when you get into Calculus level stuff

Writing AutoIt scripts since

_DateAdd("d", -2, _NowCalcDate())
Link to comment
Share on other sites

You want to make sure that the user KNOWS that ALL measurments are to be in the METRIC system. IE m/s^2, pascals, etc.

I was able to figure this out by looking at your gravitational constant ($n_acceleration_y = -9.8)

Someone might be tempted to try to put in something that was orignally measured in feet/second and wonder why the answers came out borked.

Lofting the cyberwinds on teknoleather wings, I am...The Blue Drache

Link to comment
Share on other sites

Yes, that's why I said in my post:

EDIT: Angle is measured in degrees and velocity is measured in meters per second.

<{POST_SNAPBACK}>

P.S. - Borked is a funny word. :)
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...