Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Non-rectangular Diagram #3

Closed
kitchensjn opened this issue Jun 8, 2020 · 2 comments
Closed

Non-rectangular Diagram #3

kitchensjn opened this issue Jun 8, 2020 · 2 comments

Comments

@kitchensjn
Copy link

Thank you for making this library!

Currently, the user can set the width and height of the diagram, forming a rectangular frame that acts as the outer boundary. I'm looking to use a Perlin Noise Loop (or any non-rectangular shape) to act as this outer boundary instead. Do you have any insights into how to bound your diagram in that fashion? This feature may not have justification to be added to the base library.

@Dozed12
Copy link
Owner

Dozed12 commented Jun 9, 2020

I would say the best way would be to use the non-rectangular shape you generate just as an alpha mask on top of the rectangular voronoi diagram produced by the library (https://p5js.org/reference/#/p5.Image/mask). For the dimensions of the rectangular background diagram you can calculate the bounding box of your shape and use its width and height.

Something like this (simple example without using bounding box):

Base diagram
alt

Diagram with shape mask
alt

Diagram cutout of shape
alt

As for specifically placing voronoi points inside your shape your best bet would be to triangulate your shape (https://en.wikipedia.org/wiki/Polygon_triangulation) and then pick a random point inside a random triangle (https://stackoverflow.com/questions/19654251/random-point-inside-triangle-inside-java). Keep in mind for proper distribution of points it is important to consider the area of each triangle when selecting a triangle.

Hope that helps.

@kitchensjn
Copy link
Author

kitchensjn commented Jun 9, 2020

I appreciate the quick and thorough reply! Thank you. This should work well within my application. I will close this issue and post a follow up reply with a code example once I work through it for anyone who is interested.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants