My Math Forum Hypotenuse path from point A to B

 Geometry Geometry Math Forum

March 14th, 2019, 07:48 AM   #1
Newbie

Joined: Mar 2019
From: Norway

Posts: 1
Thanks: 0

Hypotenuse path from point A to B

Hi

I'm working on a simpel path for a target in a game. I want the target to diagonally through the hypotenuse since I know the legs. The target as the coordinates of point A, being the start point, and point B, the end point. The target also has a speed on which it should move n amount of pixels per frame. My simple formula is pretty much newXCoordinate=(legX/hypotenuse)*speed and newYCoordinate = (legY/hypotenuse)*speed.

In reality it move like the yellow like shown in the image attached. I'm guessing it's because each pixel movement is calculated as integers and not float number. So the target can't move in decimal pixels but only whole pixels at a time.

An alternative would be to calculate with memory. Example, for each 2 x-axis pixels the target move, it also moves 3 pixel in the y-axis, but every other time the target moves in the x-axis it needs to move 4 pixels in the y-axis. Or does anyone have a better idea?
Attached Images
 Greenshot 2019-03-14 16.00.04.png (16.3 KB, 2 views)

 Tags hypotenuse, hypothenuse, path, point

 Thread Tools Display Modes Linear Mode

 Similar Threads Thread Thread Starter Forum Replies Last Post Bio Math 9 March 13th, 2017 10:59 PM davedave Geometry 6 October 1st, 2016 11:40 PM aise5668 Real Analysis 3 March 5th, 2012 06:36 PM FeebleBrain Algebra 4 January 24th, 2011 12:48 AM bonsai6 Algebra 2 August 23rd, 2007 10:19 AM

 Contact - Home - Forums - Cryptocurrency Forum - Top