# Caculating triangular grid position

This topic is 4961 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

##### Share on other sites
For this problem I would use barycentric coordinates, or the parametric representation V0+uE0+vE1. If you need help with the math, I'd be glad to post details tomorrow. The only thing I'm not quite clear on is what 'a' and 'b' are, and how they map to the triangle grid. (It's probably obvious from the equations you posted, but I couldn't pick it up at a glance...)

##### Share on other sites
Yes, help with the math would be great. A and B are the cell coordinates. So the very first cell would be A=0 and B=0 and then the cell to the right of that would be A=1 B=0 , ect.

##### Share on other sites
At first I rejected the mouse map idea due to the triangles flipping up and down... However now I believe that I can infact make the mouse map work..

Basically I need to make a grid so that every other tile has a box (so one box will intersect three tiles, 1 right side up and 2 down but only half way)

Then I make a mouse map and test to see if the mouse pointer is over the blue area (then we stay at the xindex*2,yindex) otherwise if it is red then we do xindex*2-1 (red fills the left side) ... if it is yellow then we do xindex*2+1 (yellow fills the right side)

This SHOULD work, I am 90% sure I can code the formulas and such to make this method work. IF it does work, I will repost here so that other people can learn how to do it as well :).

This way is not purely mathmatical but it also doesn't involve huge amounts of looping or trig heh.

Thanks for the help so far :).

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

(You must login to your GameDev.net account.)

• 13
• 9
• 15
• 14
• 46
• ### Forum Statistics

• Total Topics
634060
• Total Posts
3015300
×