Pages

Sunday, January 18, 2026

Insomnia

If a torus had right angles on all sides what would you call it.  I would say a ring or sleeve but I suspect there may be a more precise term.  I need to write code that removes everything around a cylinder. After milling, a cylinder at a specified location and height remains and everything else has been filled away. 

2 comments:

  1. From Grok:

    A torus generated by revolving a circle produces the classic donut shape with curved surfaces. However, if you revolve a rectangle (or square) instead, the resulting shape has flat faces and right angles where those faces meet, forming a ring-like structure with a rectangular cross-section. This is commonly called a square toroid (or rectangular toroid, depending on the aspect ratio of the cross-section). It's a type of toroid, which is the more general term for surfaces of revolution that aren't limited to circular profiles.

    Regarding your milling scenario: It sounds like you're describing a subtractive manufacturing process (e.g., CNC milling) where you start with a stock block of material and remove everything except a cylindrical feature at a specific position and height, effectively leaving a standalone cylinder (like a boss or pillar) protruding from the base or isolated entirely.

    If you need code to model or simulate this (e.g., for generating toolpaths, voxel-based removal, or 3D visualization), it depends on the software/environment. Here's a simple example in Python using NumPy and Matplotlib to simulate a 3D voxel grid where the "milling" removes voxels outside a defined cylinder—essentially creating a binary 3D array representing the remaining material. You could adapt this for actual CAD/CAM by exporting to STL or integrating with libraries like PyCAM or OpenSCAD.

    Python:

    import numpy as np
    import matplotlib.pyplot as plt
    from mpl_toolkits.mplot3d import Axes3D

    # Define grid parameters (e.g., a 50x50x50 voxel block)
    grid_size = 50
    x, y, z = np.mgrid[0:grid_size, 0:grid_size, 0:grid_size]

    # Specify cylinder location (center at x=25, y=25), radius, and height
    center_x, center_y = 25, 25
    radius = 10
    height = 40 # Cylinder from z=0 to z=height

    # Create a mask for the cylinder: 1 inside cylinder, 0 outside (milled away)
    dist_from_center = np.sqrt((x - center_x)**2 + (y - center_y)**2)
    cylinder_mask = (dist_from_center <= radius) & (z <= height)

    # The 'remaining_material' is now the cylinder voxels set to 1, everything else 0
    remaining_material = np.zeros((grid_size, grid_size, grid_size))
    remaining_material[cylinder_mask] = 1

    # Visualize the result (optional: plot the remaining voxels)
    fig = plt.figure()
    ax = fig.add_subplot(111, projection='3d')
    ax.voxels(remaining_material, facecolors='blue', edgecolor='k')
    ax.set_xlabel('X')
    ax.set_ylabel('Y')
    ax.set_zlabel('Z')
    plt.show()
    To arrive at this:

    1. Set up a 3D grid using np.mgrid to represent the stock material.
    2. Calculate the radial distance from each point to the cylinder's axis.
    3. Apply a boolean mask to keep points within the radius and height (logical AND).
    4. Set the grid values accordingly—1 for remaining, 0 for removed.
    5. (Optional) Use ax.voxels for a 3D plot to verify.

    ReplyDelete
    Replies
    1. Thanks. I figured out how to add a parameter to my existing circle pocket code the do this,

      Delete