Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6650313
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T00:52:41+00:00 2026-05-26T00:52:41+00:00

Having problems with the output of this formula: typedef struct { float t, Vx,

  • 0

Having problems with the output of this formula:

typedef struct
{
    float t, Vx, Vy, Px, Py;
} datapoint; 

datapoint *data;
data = malloc(steps * sizeof(datapoint));

data[0].Vx = (20*cos(30));           //30 is changed to radians
data[0].Vy = (20*sin(30));
data[0].Px = 0;
data[0].Py = 0;

steps=100;
i=1;

do
{
    printf("Time: %.2f\t",i*q5);

    // X
    data[i].Vx = data[i-1].Vx ;//- CalculateDrag(data[i-1].Vx, q4);
    data[i].Px = ((data[i-1].Px) + ((data[i].Vx) * i));

    printf("X = %.2f\t",data[i].Px);

    // Y
    data[i].Vy= data[i-1].Vy - (9.81)*i; //- CalculateDrag(data[i-1].Vy,q4);
    data[i].Py= data[i-1].Py + (data[i].Vy * i);

    printf("Y = %.2f\t", data[i].Py);

    printf("\n");
    i++;
} while(((data[i].Py) >0) && (i<=steps));

The output should look like this:

Time 0.10s: X = 1.73m Y = 1.00m
Time 0.20s: X = 3.46m Y = 1.90m
Time 0.30s: X = 5.20m Y = 2.71m
....
....
Time 2.00s: X = 34.64m Y = 1.36m
Time 2.10s: X = 36.37m Y = 0.40m
Time 2.20s: X = 38.11m Y = -0.66m
Landed at X = 38.11 at time 2.20s

But instead it prints out other values. Tried what i can but think there is maybe faulty code with the formula.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T00:52:42+00:00Added an answer on May 26, 2026 at 12:52 am

    It looks like you’re trying to incrementally update values but are using absolute time values:

    data[i].Px = ((data[i-1].Px) + ((data[i].Vx) * i));
    

    since you’re using the previous step value to calculate the new value (LHS of +) but adding on the current speed multiplied by the total time so far (RHS of +).

    You either need to use absolute values:

    data[i].Px = ((data[0].Px) + ((data[i].Vx) * i));
    

    or incremental values:

    data[i].Px = ((data[0].Px) + ((data[i].Vx) * t)); // where t is the time step
    

    This works OK with Px since there’s no acceleration component. The Py component has an acceleration component so doing the incremental version will introduce an error, since speed is not constant throughout the time step interval. You are approximating a curve with a series of linear sections.

    I guess you’re trying to implement the following:

    s = ut + at2/2

    and trying to find the point where s.y is zero (hitting the ground). Rather than using an array and incrementally calculate s, use the above equation like this:

    t = 0;
    u = initial vector; 
    a = gravity;
    
    do
    {
      t += time step;
      s = u * t + a * t * t / 2;
    } while (s.x >= 0);
    

    You would also benefit from using a vector library (not std::vector, but a math vector), then you can write the equation just like in the code above and not calculate the x and y parts individually. It will also be easier to migrate to a 3D system.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is a rather simple question, I am having problems inserting data from Javascript
Im having problems building a query with the linq to sql data query expression
I am having problems manually looping through xml data that is received via an
I am having great problems solving this one: I have a mysql database encoding
Basically i am having problems with my code - this is homework so would
Having a few problems with output buffering. Mainly, I'm trying to run output buffering
I'm having problems with this getopt() code in a script that I'm writing which
I am attempting to parse an output file for some data, and am having
Im having problems displaying records to my view when passing viewdata to a user
I have recently started having problems with TortoiseCVS, or more specifically with plink, the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.