Jump to content
Sign in to follow this  


Recommended Posts

Posted Image Edited by AngelofDeath

Share this post

Link to post
Share on other sites

I am not sure what exactly the issue is. However, there were some things I noticed. You are using degrees, whereas Autoit likes units in Radians. Also the formula for the horizontal distance at which the projectile will reach its max height is incorrect, IF you are launching from a hill and $y does not equal 0. That is it will not be a simple (max Distance /2). In general, rather then have only three points, you could have say 10. Find the max distance divide that by 10, and plot each point.

Here are some of the changes:

#AutoIt3Wrapper_Au3Check_Parameters=-q -d -w1 -w2 -w3 -w4 -w5 -w6
#include <GDIPlus.au3>

; Distance traveled
; g: the gravitational acceleration
; a: the angle at which the projectile is launched
; v: the velocity at which the projectile is launched
; y: the initial height of the projectile
; d: the total horizontal distance traveled by the projectile
Local $g = 9.81
Local $a = 45
Local $v = 100
Local $y = 0
Local $d = (($v * Cos( degToRad($a) ) ) / $g) * ($v * Sin( degToRad($a) ) + Sqrt((($v * Sin( degToRad($a) )) ^ 2) + (2 * $g * $y)))

; Height at x
; x: given distance
; z: the height of the projectile at the given distance
Local $x = Int($d / 2)      ;  ****This is incorrect if the launch height $y is not 0.
Local $z = $y + ($x * Tan(degToRad($a))) - ($g * ($x ^ 2)) / (2 * (($v * Cos(degToRad($a))) ^ 2))

ConsoleWrite( "Distance " & $d & @CRLF)
ConsoleWrite( "Height " & $z & @CRLF)
ConsoleWrite( degToRad(180) )

; Create the GUI;
Local $hWnd = GUICreate("Trajectory Test", 800, 600)

Local $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hWnd)
Local $hPen = _GDIPlus_PenCreate(0xFFFFFFFF, 1)

Local $aPoints[4][2] = [[3]]

$aPoints[1][0] = 0 ; x of launch point
$aPoints[1][1] = 600-$y ; y of launch point

$aPoints[2][0] = $x ; x of apex
$aPoints[2][1] = 600 - $z ; y of apex

$aPoints[3][0] = $d ; x of landing point
$aPoints[3][1] = 600 ; y of landing point  *** This should be the ground point no matter what e.g. 600

_GDIPlus_GraphicsDrawCurve($hGraphic, $aPoints, $hPen)

While 1
    Switch GUIGetMsg()
        Case -3


Func degToRad($deg)
    Local $Pi = 4 * ATan(1);
    return ( (2*$Pi) * ($deg / 360) )

It is not correct, exspecially if you are above ground height, however, perhaps it is more correct, and get you started on the right path. Sounds like a fun project.

Share this post

Link to post
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
Sign in to follow this