Returning each co-ord between two points of a linear line

In summary, the conversation discusses the need to create an equation or solution for returning the coordinates between two points in a line for a game. The points are dynamic and the goal is to return each tile that the line passes through. One suggestion is to calculate the distance between the two points and then add or subtract one from each coordinate until the distance is reached. This process can be updated in real time without any issues.
  • #1
boo1234
1
0
Hi,

I need to come up with an equation/solution/way to return each of the co-ordinates between two points in a line.

This is for a game, I want to return the co-ords between two player locations.

Let's say for example player one is at 20,5 and player two is at 41,5

I need to return:

21,5
22,5
23,5
24,5
25,5

and so on up to 41,5

The points are dynamic

Help appreciated.

To clarify I need to return each TILE that the 'line' passes through between two players.
 
Physics news on Phys.org
  • #2
Well you can just take [itex]x_2-x_1[/itex] that gives you the distance [itex]x_2[/itex] to [itex]x_1[/itex] let's call it a, then do the same for y and call it b, now simply add one to each co-ordinate or take one if a or b are negative to [itex]x_1[/itex] and [itex]y_1[/itex] respectively until a=[itex]x_2-x_1[/itex] or until b=[itex]y_2-y_1[/itex]. If a and b respectively are equal to [itex]x_2-x_1[/itex] and [itex]y_2-y_1[/itex] then stop. Should provide you with each co-ordinate between the two points. Being a computer I'm sure it can update that in real time with no problems.
 
Last edited:

1. What is a linear line in mathematics?

A linear line is a straight line that follows the equation y = mx + b, where m is the slope of the line and b is the y-intercept. It can also be described as a set of points that have a constant rate of change.

2. How do you calculate the slope of a linear line?

The slope of a linear line can be calculated by finding the change in y values over the change in x values between two points on the line. This can be represented by the formula (y2 - y1) / (x2 - x1).

3. What is the significance of returning each co-ordinate between two points of a linear line?

Returning each co-ordinate between two points on a linear line allows you to plot all the points on the line and visualize its overall shape and direction. It also helps in calculating the slope of the line and determining its equation.

4. How do you find the equation of a linear line?

The equation of a linear line can be found using the slope-intercept form, y = mx + b, where m is the slope of the line and b is the y-intercept. You can also find the equation by using two points on the line and plugging them into the slope formula, (y2 - y1) / (x2 - x1).

5. Can a linear line have a negative slope?

Yes, a linear line can have a negative slope. This means that the line is decreasing from left to right and has a downward direction. A negative slope can also be represented as a negative value for m in the slope-intercept form, y = mx + b.

Similar threads

  • Calculus and Beyond Homework Help
Replies
5
Views
2K
  • Calculus and Beyond Homework Help
Replies
2
Views
4K
  • Calculus and Beyond Homework Help
Replies
2
Views
1K
Replies
10
Views
2K
Replies
1
Views
858
Replies
13
Views
1K
  • Set Theory, Logic, Probability, Statistics
Replies
2
Views
481
  • Calculus and Beyond Homework Help
Replies
1
Views
1K
  • Calculus and Beyond Homework Help
Replies
2
Views
1K
Back
Top