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

Click For Summary
SUMMARY

The discussion focuses on calculating the coordinates between two points on a linear line for a game scenario. The specific example provided involves player one at coordinates (20,5) and player two at (41,5). The solution involves determining the distance between the x-coordinates and y-coordinates, then incrementally adding to the starting coordinates until reaching the endpoint. This method effectively returns each tile that the line passes through, ensuring real-time updates are feasible.

PREREQUISITES
  • Understanding of coordinate systems in 2D space
  • Basic knowledge of linear equations
  • Familiarity with programming concepts for real-time updates
  • Experience with game development frameworks
NEXT STEPS
  • Implement Bresenham's Line Algorithm for efficient coordinate calculation
  • Explore real-time rendering techniques in game development
  • Learn about tile-based game design principles
  • Investigate optimization strategies for dynamic coordinate updates
USEFUL FOR

Game developers, software engineers, and anyone involved in creating tile-based games or real-time coordinate calculations will benefit from this discussion.

boo1234
Messages
1
Reaction score
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
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:

Similar threads

Replies
5
Views
2K
  • · Replies 2 ·
Replies
2
Views
4K
Replies
1
Views
1K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 10 ·
Replies
10
Views
2K
  • · Replies 13 ·
Replies
13
Views
3K
  • · Replies 2 ·
Replies
2
Views
2K