Posts

Speeding up nesting calculations

Image
Algorithms for free-form nesting has a cost that depends on the complexity of the polygons that represent the parts to be placed. The more complex (the more points) these polygons are, the longer the computing time.

One might accept a slight waste of material if that can speed up the nesting significantly. The obvious idea is to simplify the polygons and for that task, there is a considerable amount of algorithms available.

However, there is a bit of a catch in our case: If the simplification process renders a new polygon that is slightly smaller than the original one, this could be a problem as the actual part will not fit in the space allocated for it by the nesting software.


The simplification performed by the red arrow creates a new polygon that, while it has fewer points, it cannot contain the original polygon inside and so it would be a bad idea to use the new for nesting purposes. On the other hand, the green arrow simplification does create a new polygon with fewer points that…

Another stepper motor

Image
I was looking for a simple mock-up to be used to explain the operation of a stepper motor to my students. This is what I came up with:
Just four coils on the edges of a plus-sign shape, where the two horizontal coils are connected in serial in a way that they create opposite polarity fields. Same arrangement for the two vertical coils. So we end up with a vertical and a horizontal coil. Once this is set, we use a pill-shaped magnet that will align with the vertical or horizontal magnetic field created by the coils.


What is even better, current is ramped-up on one axis while it is ramped-down on the other, a smoother movement can be achieved (aka micro-stepping).

Of course, that pill-shaped magnet will look familiar to you if you ever have been to a chemistry lab as they are used for magnetic stirrers.

So for powering this "motor", I have used a stepper motor driver A4988 and as you can see, if field changes are fast enough, the rotor can spin and even stir a liquid.

Cleaning a Java Area object

Image
To determine the projection of a given 3D part, I am slicing the parts in a sequence of cuts at different heights. Each cut creates one or more perimeters or rings. The approximated desired projection is obtained by performing the union of each cut.   The image above represents the output perimeter in red color, and the number tells me there is just one. Each perimeter start is marked by a circle and its end by a square. The image below, however, does have two different output perimeters, that is, the vertical projection can be decomposed in two different disconnected areas.
 I am coding in Java and using the Area class from java.awt. The main reason is that the class does include a method to do the union of areas.  However, after some weird results and some debugging, I realized the output of such a union method is not always clean. Sometimes the output is polluted with some additional paths that are not really useful or valid. In my case, I was getting some paths consisting in just…

When the top of a cut is not that simple

Image
In the previous entry, I discussed how the silhouette of a cut, which would be a closed polygonal line, could be turned into a triangulated surface so these triangles could form a closed lid for the sliced triangular mesh.

But there are many cases when that surface is not that simple as a closed polygonal line. So the general case is a little bit more challenging. Let us see some sample cases in the image below:
So the simple case I talked about would be the circle label with the number 1. But the rest of the cases 2,3, and 4 are a bit trickier.

Case 2: We have a hole inside the exterior cut. That would be the result of cutting a tube-like shape. Here we do not want to cover the whole circle as in case number 1, but we want to keep the hole uncovered. Luckily, the Earcut library handles the cases where the external polygonal line encloses an area with one or more holes. But we still need to tell the library which points delimit the external perimeter and which ones are the perimeter of…

Closing the hole after cutting a triangular mesh

Image
Once a triangular mesh is cut by an intersecting plane, the resulting halves are no longer a water-tight mesh, because some holes are created by the cutting action of the plane.

In the image here, the volume of a [solid] hat was cut by a vertical plane, splitting it in two. In order for this half to be back a 2-manifold triangular mesh, all the triangles with black edges have been added to create a flat surface that covers what the cut plane would otherwise reveal (the inside of the hat).

The problem is how given a certain polygon, like the red polygonal line here, a collection of triangles can be created to cover entirely all the area delimited by such a perimeter (aka polygon triangulation).

The problem gets even more interesting once we consider that some meshes can present holes inside these perimeters obtained after cutting the mesh with a plane.

Fortunately, there are different algorithms to solve that problem, and I will settle with the so-called Ear clipping. Fortunately, the…

Cutting a triangular mesh and keeping the pieces

Image
When we use a plane to cut a triangular mesh, several cases can be considered. If there is a non-null intersection between the plane and a given triangle, there are mostly five different cases:


The plane contains one vertex of the triangle: not very useful for cutting purposes if the rest of the triangle lays above the cutting plane and we want to keep all that is below.The plane contains two vertices of the triangle, then the intersection is a line segment but we will only keep that triangle if the other vertex is below the cutting plane.The plane contains three vertices of the triangle: that is a keeper.The plane does not contain any vertices of the triangle, but there is an intersection with two of the edges: this is what we will talk about today here.A fifth case can be considered when the plane contains one vertex but the two other are on opposite sides of the plane, and it can easily be incorporated to the previous case. The following picture shows us a couple of triangles of a m…

Enterprise WPA and ESP32

Image
I recently gave Adafruit's IO service a try. You can get a few data sensor feeds recorded and graphed on the web. They have a somehow limited version for free and a more complete offering for paying customers.

A current project required to record a few sensor samples per minute and Adafruit's free service seemed to fit the bill. I was using ESP32 with BME280 sensor to gather humidity, temperature, and atmospheric pressure and to store it somewhere in the cloud.

I was testing this on campus, where we have a corporate wifi network that uses a Radius server for PEAP authentication. I assumed ESP32 could only use WPA with a pre-shared key but I was wrong. I googled around and found that some people were using it with Eduroam. Eduroam is a European-wide Academic wifi network and it is present in our campus too, so what harm was in trying?

I found this code that might work so I tried it out, and it did work at the first try! Brilliant!


But there were a couple of details that did not…