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

points_on_circle function #14

Open
anandology opened this issue Jun 27, 2021 · 6 comments
Open

points_on_circle function #14

anandology opened this issue Jun 27, 2021 · 6 comments
Assignees

Comments

@anandology
Copy link
Contributor

It would be interesting to have a function that returns points equidistant on a circle.

points = points_on_circle(n=5, r=100)
shape = polygon(points)

These points can be used to create very intersting shapes by connecting to each other point etc. This will allow the students to achive all these shapes without worrying about sine and cosine.

I'm not particularly happy with the name points_on_circle. Another option is crange, just like range, but returns points on a circle.

pentagon = polygon(crange(n=5))  # r would default to 100

It feels quite useful, but at the same time it also feels like this function doesn't really belong to the joy library and doesn't go well with all other functions.

@amitkaps what do you think?

@anandology anandology self-assigned this Jun 27, 2021
@anandology
Copy link
Contributor Author

I could do:

c = circle()
points = c.get_points(n=5)

Looks like it is extensible.

e = ellipse()
points = e.get_points(n=5)
r = rectangle(w=200, h=100)
points = e.get_points(n=8) # any multiple of 4 will work

This approach an be extended to a line or polygon as well.

But I have not introduced methods yet. Not sure, if it is a good idea to do it this way.

@amitkaps
Copy link

It will be very useful. You should look at these two function in SVG which do the basic stuff.

It should work on any path & shape - so I would suggest to name it as a general function that work on Path and Shapes. e.g. get_point_on_path and get_point_on_shape

For inspiration & examples, also look at Coordinator Library - https://github.com/spotify/coordinator which extends it beyond paths to shape. Write up about the library @ https://engineering.atspotify.com/2018/03/02/introducing-coordinator-a-new-open-source-project-made-at-spotify-to-inject-some-whimsy-into-data-visualizations/

@anandology
Copy link
Contributor Author

It will be very useful. You should look at these two function in SVG which do the basic stuff.

* [SVGGeometryElement.getPointAtLength()](https://developer.mozilla.org/en-US/docs/Web/API/SVGGeometryElement/getPointAtLength)

* [SVGGeometryElement.getTotalLength()](https://developer.mozilla.org/en-US/docs/Web/API/SVGGeometryElement/getTotalLength)

It should work on any path & shape - so I would suggest to name it as a general function that work on Path and Shapes. e.g. get_point_on_path and get_point_on_shape

Rather than having to get individual points by specifying length, I think it would be better have a function that returns a list of n points at equal distance on the shape/path.

Also, instead of having a function specific to path or shape, I suggested a method get_points that works on every primitive shape.

One option could be to have a global function get_points(shape, n), but I'm not convinced to add this to the global namespace.

@anandology
Copy link
Contributor Author

For inspiration & examples, also look at Coordinator Library - https://github.com/spotify/coordinator which extends it beyond paths to shape. Write up about the library @ https://engineering.atspotify.com/2018/03/02/introducing-coordinator-a-new-open-source-project-made-at-spotify-to-inject-some-whimsy-into-data-visualizations/

Thats looks quite interested!

@amitkaps
Copy link

Path and Shapes are different - similar to Stroke and Fill (for Colors). So Points on a Path and Points in a Shape have different meaning.

Right now the library does differentiate between the two - so may be later.

Also, worth thinking about what happens when you draw multiple shapes? Or is this going to be limited to primitive shapes (line, rectangle, circle) only.

@anandology
Copy link
Contributor Author

Path and Shapes are different - similar to Stroke and Fill (for Colors). So Points on a Path and Points in a Shape have different meaning.

Agreed. But I'm trying to see if it is possible to unify that.

Right now the library does differentiate between the two - so may be later.

Thanks for the caution. I'll read up a bit and see if I need to model it differently.

Also, worth thinking about what happens when you draw multiple shapes? Or is this going to be limited to primitive shapes (line, rectangle, circle) only.

It is only for primitive shapes right now. I can't think of a way to generalize this.

However, I would love to find a way to identify a bounding box for any shape. It could be just the center of the shape and width and height.

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