Physics help!-VBForums
Results 1 to 12 of 12

Thread: Physics help!

  1. #1

    Thread Starter
    Member
    Join Date
    Dec 2017
    Posts
    34

    Physics help!

    Hello
    I wanna make a program that calculates maximum height, horizontal range, time of flight, and the time of maximum height, and this is called projectile motion, I wanna the codes of equations to calculate these things with two given data which are primary speed and the angel. It is possible because I saw someone who made it with these things but it's arabic

  2. #2
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    97,712

    Re: Physics help!

    Yes it is possible, but it's not really for us to do your homework for you. How about you put some thought into it, use what you have learned in class, make an effort and then post back when you encounter an actual issue? There are plenty of people here who are willing to help but just doing it for you is not helping; it's doing it for you. Also, you say that you want code but you have posted this in the maths forum. If you are looking to write code in a particular language then you should post in the forum for that language. The maths forum is about mathematical formulae and how to use them, but I'm fairly sure that you can easily find the appropriate mathematical formulae for those calculations. If you want help implementing those formulae in a particular programming language then we'd at least have to know what that language is. Still, if we see no effort at all on your part, most people aren't going to just do your work for you. If you're not prepared to put any effort into this on your own behalf, why should we? Make some effort and you'll find plenty of people who will do so too.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3
    Hyperactive Member 2kaud's Avatar
    Join Date
    May 2014
    Location
    England
    Posts
    457

    Re: Physics help!

    maximum height, horizontal range, time of flight, and the time of maximum height
    These are standard projectile equations (assuming constant mass and g). Any advanced level maths book will have them. They are derived from the standard linear equations of motion.
    v = u + at
    v2 = u2 + 2as
    s = ut + 1/2 at2

    (note v2 means v squared etc)

    A quick internet search will provide plenty of sites explaining projectile motion.
    All advice is offered in good faith only. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/

    C++17 Compiler: Microsoft VS2017 (15.5.7)

  4. #4

    Thread Starter
    Member
    Join Date
    Dec 2017
    Posts
    34

    Re: Physics help!

    here is my code;
    Const Gravity = 9.8
    Dim Angel As Double
    Dim initialvelocity As Double
    Angel = Val(txtAngel.Text)
    initialvelocity = (txtInitialVelocity.Text)
    Dim angelradian As Double
    angelradian = Angel * 2 * Math.PI / 360
    Dim horizontalrange As Double
    horizontalrange = 2 * Math.Cos(angelradian) * initialvelocity * initialvelocity * Math.Sin(angelradian) / Gravity
    Dim maximumheight As Double
    maximumheight = initialvelocity * initialvelocity * Math.Sin(agnelradian) * Math.Sin(angelradian) / 2 * Gravity
    Dim timeofflight As Double
    timeofflight = 2 * Math.Sin(angelradian) * initialvelocity / Gravity
    Dim timeofmaximumheight As Double
    timeofmaximumheight = timeofflight / 2
    txtAngelRadian.Text = Str(angelradian)
    txtHorizontalRange.Text = Str(horizontalrange)
    txtMaximumHeight.Text = Str(maximumheight)
    txtTimeOfFlight.Text = Str(timeofflight)
    txtTimeOfMaximumHeight.Text = Str(timeofmaximumheight)
    but maximum height is bugged, it doesn't calculate the equations, it gives zero

  5. #5
    Hyperactive Member 2kaud's Avatar
    Join Date
    May 2014
    Location
    England
    Posts
    457

    Re: Physics help!

    range is (v * v * sin(2 * a)) / g

    max height is (v * v * sin(a) * sin(a)) / (2 * g)

    time flight is (2 * v * sin(a)) / g

    time max height is (v * sin(a)) / g which is (time flight) / 2

    so
    Code:
    maximumheight = initialvelocity * initialvelocity * Math.Sin(agnelradian) * Math.Sin(angelradian) / (2 * Gravity)
    All advice is offered in good faith only. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/

    C++17 Compiler: Microsoft VS2017 (15.5.7)

  6. #6
    Hyperactive Member 2kaud's Avatar
    Join Date
    May 2014
    Location
    England
    Posts
    457

    Re: Physics help!

    Code:
    angelradian = Angel * 2 * Math.PI / 360
    which simplies to

    Code:
    angelradian = Angel * Math.PI / 180
    Code:
    horizontalrange = 2 * Math.Cos(angelradian) * initialvelocity * initialvelocity * Math.Sin(angelradian) / Gravity
    2 * cos(a) * sin(a) is sin(2 * a)

    so
    Code:
    horizontalrange = initialvelocity * initialvelocity * Math.Sin(2 * angelradian) / Gravity
    All advice is offered in good faith only. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/

    C++17 Compiler: Microsoft VS2017 (15.5.7)

  7. #7

    Thread Starter
    Member
    Join Date
    Dec 2017
    Posts
    34

    Re: Physics help!

    I know these rules, but it still gives zero -_-

  8. #8
    Hyperactive Member 2kaud's Avatar
    Join Date
    May 2014
    Location
    England
    Posts
    457

    Re: Physics help!

    See my code in post #5, You have missing brackets highlighted in red.
    All advice is offered in good faith only. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/

    C++17 Compiler: Microsoft VS2017 (15.5.7)

  9. #9

    Thread Starter
    Member
    Join Date
    Dec 2017
    Posts
    34

    Re: Physics help!

    I saw them and I changed it but it still give zero

  10. #10
    Hyperactive Member 2kaud's Avatar
    Join Date
    May 2014
    Location
    England
    Posts
    457

    Re: Physics help!

    I'm not a VB programmer, but are you getting integer division truncation?

    Mathematically,

    Code:
    angelradian = Angel * Math.PI / 180
    is equivalent to
    Code:
    angelradian = Angel * 2 * Math.PI / 360
    so both should provide the same result.

    Does

    Code:
    angelradian = Angel * Math.PI / 180.0
    produce the correct value of angelradian?

    You also have a spelling error

    Code:
    maximumheight = initialvelocity * initialvelocity * Math.Sin(angelradian) * Math.Sin(angelradian) / (2 * Gravity)
    All advice is offered in good faith only. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/

    C++17 Compiler: Microsoft VS2017 (15.5.7)

  11. #11

    Thread Starter
    Member
    Join Date
    Dec 2017
    Posts
    34

    Re: Physics help!

    The first rule was my bad, I forgot to change 360 to 180, and the second one now it works, thanks dude.

  12. #12
    Hyperactive Member 2kaud's Avatar
    Join Date
    May 2014
    Location
    England
    Posts
    457

    Re: Physics help!

    No problem. Pleased I could help
    All advice is offered in good faith only. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/

    C++17 Compiler: Microsoft VS2017 (15.5.7)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width