quil

dabrazhe 2023-03-07T13:50:23.528739Z

quil/rotate rotates around [0 0] point, right? How can I rotate eg a rectangle in-place, i.e, around/relative to it's center?

dabrazhe 2023-03-08T10:48:19.417429Z

The problem with translation is that I need to know the actual coordinates of a primitive, before rotation, every time. This is not helpful when drawing within mapv or similar AND it does not work for ellipse..

dabrazhe 2023-03-08T10:50:20.997269Z

@srijayanth Can you elaborate on the center mode, can't find it in the api

genmeblog 2023-03-08T11:22:35.126749Z

http://quil.info/api/shape/attributes#rect-mode

genmeblog 2023-03-08T11:23:26.590889Z

It controls how arguments to rect are interpreted. It doesn't affect the rotation point though.

dabrazhe 2023-03-08T11:39:14.094749Z

Great, that helps a bit. What about other shapes, like triangle and vertex?

genmeblog 2023-03-08T11:49:04.822909Z

Only ellipse (`ellipse-mode`) is supported. Regardings triangle, there are more than 70k of definitions of triangle https://faculty.evansville.edu/ck6/encyclopedia/ETC.html... The same probably applies to any other (not symmetrical) shape.

genmeblog 2023-03-08T11:53:22.249239Z

Generally you may want to find a center of the shape enclosing circle. But it's not trivial in general.

dabrazhe 2023-03-08T12:02:14.898509Z

The simplest solution so far for me is to use (q/with-translation [] (q/with-rotation [] combo, with the :center mode. But the triangles are off as expected, as you can see on the image, returned by a mapv sequence.

dabrazhe 2023-03-08T12:06:56.153469Z

Here it's more clear : )

genmeblog 2023-03-08T12:09:27.090049Z

Depends what you expect. And how you define the center of the triangle.

dabrazhe 2023-03-08T12:11:34.967469Z

What about inducing the size of the rectangle surrounding a shape and rotating it/the whole canvas in closure?

genmeblog 2023-03-08T12:21:26.738249Z

Doable. If you are on JDK, take a look at PShape which knows enclosing box size.

genmeblog 2023-03-08T12:22:24.349589Z

https://processing.org/reference/PShape.html

dabrazhe 2023-03-08T12:24:26.026379Z

If I understand you correctly, I can use Pshape with quil via interop, right?

dabrazhe 2023-03-08T12:28:13.244319Z

I am not bit on java interop, how can I access it?

genmeblog 2023-03-08T12:35:26.897639Z

Hmmm... In Processing you cal call createShape I don't see such function in quil. It's explained here: https://github.com/quil/quil/issues/165

👍 1
genmeblog 2023-03-08T12:39:58.840509Z

Maybe the easiest way is to calculate the centroid of used vertices and rotate around it. Centroid is just an average of point coordinates (x and y separately).

âś… 1
dabrazhe 2023-03-08T21:21:16.008469Z

Thanks everyone for help!

genmeblog 2023-03-07T13:57:20.353389Z

translate to the center of the rectangle, rotate and translate back

craftybones 2023-03-07T15:52:40.661089Z

there are two ways

craftybones 2023-03-07T15:52:56.454879Z

One is to calculate the points yourself and draw, which is painful

craftybones 2023-03-07T15:52:59.627569Z

But here is a useful snippet

craftybones 2023-03-07T15:53:30.061279Z

(q/with-translation [(+ x half-width) (+ y half-height)]
  (q/rotate angle)
  (q/translate (- half-width) (- half-height))
  (q/rect 0 0 width height))

dabrazhe 2023-03-07T16:35:12.461539Z

Thank you all. It seems to be quite a chore for such a simple operation ) Is there anything standard in the core quil lib? I guess might others have the same question

genmeblog 2023-03-07T16:55:10.373659Z

Get used to it :) It works this way in most of such libraries. With rotate/translate/scale/shear you build affine transformation of your plane. This way shapes and tranformations are separated and can be composed.

craftybones 2023-03-07T18:41:49.721819Z

I highly recommend drawing by hand until you get a hang of it, it becomes a lot easier then

craftybones 2023-03-07T18:42:51.016619Z

Alternately, you can use the center rect-mode and it’ll save you one translate call…