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 7648697
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T10:46:57+00:00 2026-05-31T10:46:57+00:00

How would I write a function to move from point1 to point2 given some

  • 0

How would I write a function to move from point1 to point2 given some time?

For example:

Point move(Point point1, Point point2, long timeInMilliseconds, int speedPerSecond)
{
  // basic stuff
  int pointsMoved = speedPerSecond * 1000 / timeInMilliseconds;
  if (point1.x == point2.x && point1.y > point2.y)
    return (new Point(point1.x, Math.min(point2.y, point1.y + pointsMoved)));
  ...
}

Yes, that’s where my sad math skills end.
How do I move if the movement is not diagonal or vertical? if there’s an angle?

BTW, I plan to recalculate the current point based on point1 and point2, I will not be updating point1 nor point2 from the caller, so caller would look like this:

Point currentPoint = move(originalPoint, finalPoint, getCurrentTime() - originalTime, 10);

The signature of the function doesn’t have to be what I mentioned. It could very well use degrees, but that’s going to be another thing to figure out, if I have to use degrees.

  • 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-31T10:46:58+00:00Added an answer on May 31, 2026 at 10:46 am

    Here’s the general motion formula:

    p = k⟨p2 – p1⟩ + p1

    p1 is the initial position. p2 is the final position. p is the current location. k is a ratio, usually between 0 and 1, that determines how much of the distance to p2 we’ve covered.

    Your function receives tn, the current time, and v, the speed from the p1 to p2. Therefore we need one additional piece to calculate k: the distance from p1 to p2. tn is in time units (t), the distance |p2 – p1| is in distance units (d), and the speed is in distance per time units (d / t). k is unitless, so we have to neutralize the units in the three values.

    d / (d / t) / t
    = d / d · t / t
    = 1

    and our units are neutralized.

    So we have:

    k = |p2 – p1| / v / tn

    The distance is easily determined via the Pythagorean Theorem, giving us k. From there we decompose the general formula into its components:

    px = k(x2 – x1) + x1
    py = k(y2 – y1) + y1

    k, being unitless despite containing elements with components, does not get decomposed.

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

Sidebar

Related Questions

I would like to write a function which will read values from a text
I'd like to write a function that would have some optional code to be
How would you write a template function that takes a variable number of homogeneous
I would like to write a function in which there are multiple Exit Function
In C++0x I would like to write a function like this: template <typename... Types>
I need to concatenate the parameters in the write function. How would I do
I'm trying to write a function that would use its first argument, then send
I'm trying to find/write a function that would perform the same operation as imlincomb
In Python, I'd like to write a function that would pretty-print its results to
I would like to write a cross-platform function in C++ that contains system calls.

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.