# SFML community forums

## Help => General => Topic started by: lockandstrike on November 17, 2013, 02:17:38 pm

Title: An Hexagon Rect
Post by: lockandstrike on November 17, 2013, 02:17:38 pm
Okay so I've seen the Rect.inl file and understood what was going on for the rect/squares but because I'm in 8th grade I don't know how to do the same for an hexagon, I just don't know the mathematical form for it. So if someone could guide me through it.

Lots of thanks, lockandstrike
Title: Re: An Hexagon Rect
Post by: Nexus on November 17, 2013, 02:26:32 pm
What do you exactly want to achieve? The term "hexagon rect" doesn't make any sense, these are two distinct shapes.

Have a look at trigonometry and basic vector algebra, after that computing the coordinates of hexagons is not difficult. But it will require you some time to read through those topics, you can't just ask here and expect an answer "that's how it works". If you don't know where to look, Wikipedia is a good start.
Title: Re: An Hexagon Rect
Post by: lockandstrike on November 17, 2013, 02:43:45 pm
As to the title I had anticipated that sort of response what I'm looking for is something of the like of
Hex<T>
.

The problem is in the 8th grade (at least in my country) the only thing were taught in terms of geometry is how to draw triangles using the compass. I'll study those subjects, but I would be very happy if could just give me a hint.

Lots of thanks, lockandstrike
Title: Re: An Hexagon Rect
Post by: eXpl0it3r on November 17, 2013, 02:49:53 pm
Hex<T>
That doesn't mean anything. What do you expect from such a class?

Most of us weren't taught programming or some parts of math in school, that doesn't mean one can't go lend a book or search online on these topics and teach them yourself. ;)
Title: Re: An Hexagon Rect
Post by: lockandstrike on November 17, 2013, 04:50:18 pm
Ok you have the
Rect<T>
class and what I want is the same but for an Hexagon. That is, a class that allows me to check if a vector is contained inside an hexagon instead of it checking if it is contained inside of a rectangle like with the Rect class
Title: Re: An Hexagon Rect
Post by: eXpl0it3r on November 17, 2013, 04:58:33 pm
So what you really want is just a collision check function for point-inside-hexagon, why don't you just say that? ::)

The main purpose of sf::Rect<T> is to represent a rectangle through it's position and size. The "collision" functions are just some optional goodies.

Have you tried googling? For instance you could use the keywords: "point in hexagon" :)
Title: Re: An Hexagon Rect
Post by: zsbzsb on November 17, 2013, 05:09:08 pm
There are many things to consider when using hex based maps. One of the best resources I have ever found on hex based maps can be found here (http://www.redblobgames.com/grids/hexagons/).

http://www.redblobgames.com/grids/hexagons/ (http://www.redblobgames.com/grids/hexagons/)