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

Arc Examples? #87

Open
thestumbler opened this issue Dec 14, 2024 · 2 comments
Open

Arc Examples? #87

thestumbler opened this issue Dec 14, 2024 · 2 comments

Comments

@thestumbler
Copy link

I've read the documentation, and it seems possible to make an arc using polar_theta_lines(). I found and can reproduce the polar_r_lines() from one of the examples, but I don't see any examples of arcs. Could you provide a code snippet, please? The point I'm getting stuck on is how to build the necessary geometry.

@thestumbler
Copy link
Author

Additional remarks.

I found a suitable arc example in polar_examples.py, where polygons are in fact visually arcs of a certain thickness. I had missed this point during my initial searching through the code. You could say using polygons in the manner is akin to specifying arcs with a certain line width.

I'm struggling to fully understand the Geometry concepts. The ColumnGeometry, which seemed to be the more complex one at first, actually makes the most sense to me. The Geometry and RowGeometry are still a bit of a mystery.

Short of writing a whole tutorial, are there any further examples you could provide which elaborate on how these are used? Did you make up this Geometry concept? If not, and it's a common thing in the graphics world, are there any papers one could read that explain this in more detail?

Also, I tried to learn more by just poking around in the REPL and experimenting with Geometries. But none of the classes have a str or repr method. It's difficult to peek inside and see what's going on. Could you add those to these classes?

@corranwebster
Copy link
Contributor

An arc is a line of constant theta in polar coordinates, so you to create a single arc geometry centred at 120, 120 with radius 100, from 45 degrees subtending an angle of 90 degrees, you could do something like:

arc_geom = polar_theta_lines(120, 120, [(100, 45, 90)])

... and this example just made me realise that I haven't exposed the PolyLines class via the surface ... so when I fix that you should be able to do something like:

surface.poly_lines("DRAWING", arc_geom, ...)

but until then you'll have to do the low-level

arc = PolyLines(arc_geom, ...)
surface.add_shape("DRAWING", arc)

To create a circular wedge like the screen of a meter-style display, you might use a polar rectangle instead, eg.:

window_geom = polar_rect(120, 120, [(90, 240, 20, 60)])
surface.polygons("DRAWING", window_geom, ...)

(this goes from radius 90 to radius 110 = 90+20, and angle 240 to 300).

For Geometries more generally, there is a tutorial section on geometry here: https://unital.github.io/tempe/user_guide/tutorial.html#shapes-and-geometry which hopefully gives the basic ideas.

The geometry concept comes from ideas in Wilkinson's Grammar of Graphics, together with the practical considerations around speed and memory that make drawing many similar objects at once is faster and more efficient than having many independent objects. It also has some inspiration from OpenGL's drawing primitives.

In terms of the objects:

  • RowGeometry is like a list of shape coordinates (ie. 1st shapes coords, then second shapes coords, etc.), but stored more efficiently in memory.
  • ColumnGeometry is the transpose of RowGeometry: the first coordinates of all the shapes, then the second coordinates of all the shapes, etc
  • StripGeometry is more complex, and is intended to be used to efficiently store coordinates when there is overlap (eg. when you have a set of line segments where the end of one line segment is the start of the next) and you don't want to store the numbers twice. This concept comes from OpenGL where they have line strips and triangle strips, for example.

You don't have to use Geometry objects if you don't want to. You can just use lists of tuples of coordinates if you want: the geometries are just for memory efficiency.

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