Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » Nearest point on Hexagon
- MrAlwaysNeedsHelp
-
4 posts
Nearest point on Hexagon
I want to make a game like this https://scratch.mit.edu/projects/131556042/ but using a Hexagon. It's simple to do it in a circle, but how to do it in a hexagon or any other shape?
To be more specific, I just want to know where a point of a hexagon is x: and y: given a specific angle.
To be more specific, I just want to know where a point of a hexagon is x: and y: given a specific angle.
Last edited by MrAlwaysNeedsHelp (April 15, 2017 00:52:37)
- amylaser
-
500+ posts
Nearest point on Hexagon
For any general n-sided polygon, the polar equation for it is this:

Then, all you'd have to do is translate that to Scratchblocks.
The scripts are all inside this project if you want to look at them: https://scratch.mit.edu/projects/155715241/
(I went ahead and added a feature so that the red dot follows the mouse while constrained to the drawn path.)
Knowing the distance from the center (the “r” value) and the angle, you can then use the sin and cos blocks to explicitly determine the corresponding x/y values for a given angle.
Hope it helps ^.^

Then, all you'd have to do is translate that to Scratchblocks.
The scripts are all inside this project if you want to look at them: https://scratch.mit.edu/projects/155715241/
(I went ahead and added a feature so that the red dot follows the mouse while constrained to the drawn path.)
Knowing the distance from the center (the “r” value) and the angle, you can then use the sin and cos blocks to explicitly determine the corresponding x/y values for a given angle.
Hope it helps ^.^
- Scratch-Minion
-
1000+ posts
Nearest point on Hexagon
Just to say to @amylaser - What a wonderful example project!
- Discussion Forums
- » Help with Scripts
-
» Nearest point on Hexagon