How do I generate circular thumbnails with PIL?

The easiest way to do it is by using masks. Create a black and white mask with any shape you want. And use putalpha to put that shape as an alpha layer: from PIL import Image, ImageOps mask = Image.open(‘mask.png’).convert(‘L’) im = Image.open(‘image.png’) output = ImageOps.fit(im, mask.size, centering=(0.5, 0.5)) output.putalpha(mask) output.save(‘output.png’) Here is the mask … Read more

Cone to box collision

I was curious and planned to do stuff needed for this in GLSL math style anyway. So here a different approach. Let consider this definition of your cone: create a set of basic geometry primitives You need to support points,lines,triangles,convex triangulated mesh,spherical sector (cone). implement inside test between point and triangle,mesh,cone for triangle the results … Read more

Increasing accuracy of solution of transcendental equation

If I understand this correctly, you’re trying to infer (but not measure) the radius r0 of the tube from measurements for y and a. Applying the usual error propagation to your formula for r0, one obtains (an estimate for) the error of the resulting r0. In the limit of small angles (applicable here, since a(t) … Read more

How do I efficiently determine if a polygon is convex, non-convex or complex?

You can make things a lot easier than the Gift-Wrapping Algorithm… that’s a good answer when you have a set of points w/o any particular boundary and need to find the convex hull. In contrast, consider the case where the polygon is not self-intersecting, and it consists of a set of points in a list … Read more