Skip to content
TheChatArchiveThe Chat Archive
Geminigemini-2.5-pro-preview-03-25· GoogleHugging Face LMArena Human Preference 140K

design a phone stand using rhino python editor, it must be a valid closed surface, think…

From a Chatbot Arena battleThe same person sent this prompt to two anonymous models at once. Compare it with Googlegemma-3-27b-it’s answer.
  1. User

    design a phone stand using rhino python editor, it must be a valid closed surface, think hard

  2. Gemini Assistant

    Okay, let's design a robust and 3D-printable phone stand using Rhino Python, focusing explicitly on creating a valid, closed polysurface. This means using techniques that reliably result in a single, watertight solid model suitable for export (e.g., STL).

    We'll create a design with:

    1. A Stable Base: A solid block.
    2. An Angled Support: Integrated with the base, forming a wedge-like structure.
    3. A Recess for the Phone: Cut into the angled face, providing side support.
    4. A Lip: At the bottom of the angled face to prevent the phone from sliding down.
    5. A Charging Cable Cutout: Through the lip/base.
    6. Construction using Booleans: Starting with simple closed solids and using boolean operations (Difference, Union) is a reliable way to maintain a closed final object.

    Design Philosophy:

    Instead of creating separate thin parts and joining them (which can sometimes lead to boolean failures or open edges), we'll start with a larger solid block and carve out the necessary features using boolean differences. This tends to be more robust for ensuring a closed final volume.

    import rhinoscriptsyntax as rs
    import math
    
    def create_solid_phone_stand():
        """
        Designs a 3D printable phone stand as a guaranteed closed polysurface
        using boolean operations on solid primitives.
        """
        print("Starting phone stand creation...")
    
        # --- Parameters (Adjust these to fit your phone and preference) ---
    
        # Phone Dimensions (Approximate - measure your phone WITH case if used)
        phone_width = 78.0   # mm
        phone_thickness = 10.0  # mm
    
        # Stand Dimensions
        stand_base_depth = 90.0  # Depth of the stand on the table
        stand_width = phone_width + 40.0 # Overall width of the stand for stability
        stand_max_height = 100.0 # Maximum height of the back support
    
        # Design Features
        viewing_angle_deg = 70.0 # Angle of the phone face relative to the table (e.g., 60-75 is common)
        lip_height = 15.0       # Height of the front lip holding the phone bottom
        lip_thickness = 8.0     # Thickness of the front lip (front-to-back)
    
        # Phone Recess (Cutout) Parameters
        phone_recess_depth = phone_thickness * 0.6 # How deep the phone sits into the angled face
        tolerance = 1.5         # Extra space around the phone in the recess (total, so +0.75mm each side)
    
        # Charging Cable Cutout
        cable_cutout_width = 18.0
        cable_cutout_height = 8.0
        cable_cutout_depth_offset = 2.0 # How far back from the very front the cutout starts
    
        # --- Calculations ---
        viewing_angle_rad = math.radians(viewing_angle_deg)
        # Calculate the angle for shearing or defining the slanted face (relative to vertical)
        slope_angle_rad = math.radians(90.0 - viewing_angle_deg)
    
        # --- Geometry Creation ---
    
        # 1. Create the Main Solid Block (Wedge Precursor)
        # We'll create a tall block and then cut the angle.
        # Using World coordinates initially for simplicity. Origin at bottom-back-left corner.
        main_block_corners = [
            (0, 0, 0), (stand_base_depth, 0, 0), (stand_base_depth, stand_width, 0), (0, stand_width, 0),
            (0, 0, stand_max_height), (stand_base_depth, 0, stand_max_height),
            (stand_base_depth, stand_width, stand_max_height), (0, stand_width, stand_max_height)
        ]
        main_block = rs.AddBox(main_block_corners)
        if not main_block:
            print("Error: Failed to create initial block.")
            return None
        if not rs.IsPolysurfaceClosed(main_block):
            print("Error: Initial block is not closed!")
            rs.DeleteObject(main_block)
            return None
        print(f"Step 1: Initial block created (ID: {main_block})")
    
        # 2. Create the Angled Cut Plane/Volume
        # We'll define a large cutting box that removes the front portion to create the angled face.
        # The cutting plane starts at the lip position and goes up at the viewing angle.
    
        # Point on the front lip base
        cut_start_pt_x = stand_base_depth - lip_thickness
        cut_start_pt = (cut_start_pt_x, -stand_width, lip_height) # Extend beyond stand width
    
        # Point high up along the angle
        cut_end_pt_x = cut_start_pt_x - stand_max_height * math.tan(slope_angle_rad) # Use tan for X offset based on height
        cut_end_pt = (cut_end_pt_x, -stand_width, stand_max_height * 1.5) # Go higher than the block
    
        # Define a large cutting plane using 3 points (origin, x-dir, y-dir)
        # The plane's normal will be perpendicular to the desired angled face.
        plane_origin = cut_start_pt
        plane_x_axis = rs.VectorSubtract(cut_end_pt, cut_start_pt) # Vector along the slope
        plane_y_axis = (0, stand_width * 3, 0) # Vector along the width (make it large)
        cutting_plane = rs.PlaneFromPoints(plane_origin, rs.VectorAdd(plane_origin, plane_x_axis), rs.VectorAdd(plane_origin, plane_y_axis))
    
        if not cutting_plane:
            print("Error: Failed to create cutting plane.")
            rs.DeleteObject(main_block)
            return None
    
        # Create a large box aligned with this plane to use for boolean difference
        # A simpler way: Split the block with an infinite plane
        # Define split plane origin and normal vector
        split_plane_origin = (cut_start_pt_x, 0, lip_height)
        # Normal vector: Rotate world Z vector by the slope angle around Y axis
        world_z = (0,0,1)
        world_y = (0,1,0)
        normal_vector = rs.VectorRotate(world_z, -viewing_angle_deg, world_y) # Rotate Z axis
    
        split_plane = rs.PlaneFromNormal(split_plane_origin, normal_vector)
    
        # Split the block
        split_results = rs.SplitBrep(main_block, rs.PlaneSurface(split_plane, 2*stand_base_depth, 2*stand_width)) # Use a large plane surface cutter
        rs.DeleteObject(main_block) # Delete original block
    
        if not split_results or len(split_results) != 2:
            print(f"Error: Splitting the block failed or yielded unexpected number of parts ({len(split_results) if split_results else 0}).")
            if split_results: rs.DeleteObjects(split_results)
            return None
    
        # Identify the correct piece (the wedge) - usually the larger volume or the one containing a specific point (e.g., back corner)
        # Let's assume the piece containing the origin (0,0,0) is the one we want.
        wedge_body = None
        other_piece = None
        test_point = (1, stand_width / 2.0, 1) # A point definitely inside the desired wedge
        for piece in split_results:
            if rs.IsPointInSurface(piece, test_point, True, 0.1): # Check if point is inside or on boundary
                 if wedge_body is None: # Found the first piece containing the point
                     wedge_body = piece
                 else: # Found a second piece containing the point - ambiguity! Error out.
                     print("Error: Ambiguous result from split. Multiple pieces contain the test point.")
                     rs.DeleteObjects(split_results)
                     return None
            else:
                other_piece = piece
    
        if not wedge_body:
            print("Error: Could not identify the correct wedge piece after splitting.")
            rs.DeleteObjects(split_results)
            return None
    
        if other_piece: # Delete the unwanted piece
            rs.DeleteObject(other_piece)
    
        if not rs.IsPolysurfaceClosed(wedge_body):
            print("Error: Wedge body is not closed after splitting!")
            rs.DeleteObject(wedge_body)
            return None
        print(f"Step 2: Wedge body created (ID: {wedge_body})")
    
    
        # 3. Create the Phone Recess Cutout Volume
        # This box needs to be oriented along the angled face.
        recess_width = phone_width + tolerance
        recess_thickness = phone_thickness + tolerance # This dimension is perpendicular to the angled face
        recess_length = stand_max_height # Make it long enough to cut through the relevant height
    
        # Create a plane aligned with the angled face
        # Origin can be slightly above the lip, centered horizontally
        recess_plane_origin_x = stand_base_depth - lip_thickness - phone_recess_depth * math.sin(slope_angle_rad) # Offset back slightly
        recess_plane_origin_z = lip_height + phone_recess_depth * math.cos(slope_angle_rad) # Offset up slightly
        recess_plane_origin = (recess_plane_origin_x, stand_width / 2.0, recess_plane_origin_z)
    
        # Use the same normal vector as the split plane
        recess_plane = rs.PlaneFromNormal(recess_plane_origin, normal_vector)
    
        # Create the recess box using this plane
        # Define ranges for the plane's coordinate system
        x_interval = rs.CreateInterval(-recess_length / 2.0, recess_length / 2.0)
        y_interval = rs.CreateInterval(-recess_width / 2.0, recess_width / 2.0)
        z_interval = rs.CreateInterval(-phone_recess_depth, recess_thickness - phone_recess_depth) # Centered thickness around the plane
    
        recess_box = rs.AddPlaneSurface(recess_plane, x_interval.Length, y_interval.Length) # Create base surface first
        # Extrude this surface to create the box
        extrude_vec = rs.VectorScale(recess_plane.ZAxis, recess_thickness) # Extrude along plane's Z
        recess_box = rs.ExtrudeSurface(recess_box, extrude_vec)
        # Shift it back slightly so it cuts *into* the face
        shift_vec = rs.VectorScale(recess_plane.ZAxis, -phone_recess_depth)
        rs.MoveObject(recess_box, shift_vec)
    
    
        # Alternative using AddBox aligned to the plane (might be simpler if AddBox accepts plane)
        # Rhino 5 rs.AddBox might not directly take a plane like newer versions.
        # Let's stick to extrude/move. Need to make sure the extrusion creates a closed box.
        # We need to create the box geometry more manually if AddBox doesn't take a plane.
        # Let's redefine recess_box creation using corners relative to the plane:
        rs.DeleteObject(recess_box) # Delete the previous attempt
    
        half_w = recess_width / 2.0
        half_l = recess_length / 2.0 # Length along the slope
        depth = phone_recess_depth # How deep it cuts normal to the face
    
        # Corners relative to recess_plane origin
        # Back face of cutout box (deepest into the wedge)
        p1 = rs.PointAdd(recess_plane_origin, rs.VectorAdd(rs.VectorScale(recess_plane.XAxis, -half_l), rs.VectorScale(recess_plane.YAxis, -half_w)))
        p2 = rs.PointAdd(recess_plane_origin, rs.VectorAdd(rs.VectorScale(recess_plane.XAxis, half_l), rs.VectorScale(recess_plane.YAxis, -half_w)))
        p3 = rs.PointAdd(recess_plane_origin, rs.VectorAdd(rs.VectorScale(recess_plane.XAxis, half_l), rs.VectorScale(recess_plane.YAxis, half_w)))
        p4 = rs.PointAdd(recess_plane_origin, rs.VectorAdd(rs.VectorScale(recess_plane.XAxis, -half_l), rs.VectorScale(recess_plane.YAxis, half_w)))
        # Front face of cutout box (closest to surface) - offset by depth along plane's normal (ZAxis)
        offset_vec = rs.VectorScale(recess_plane.ZAxis, depth)
        p5 = rs.PointAdd(p1, offset_vec)
        p6 = rs.PointAdd(p2, offset_vec)
        p7 = rs.PointAdd(p3, offset_vec)
        p8 = rs.PointAdd(p4, offset_vec)
    
        recess_box = rs.AddBox([p1, p2, p3, p4, p5, p6, p7, p8])
    
        if not recess_box:
            print("Error: Failed to create phone recess cutout box.")
            rs.DeleteObject(wedge_body)
            return None
        if not rs.IsPolysurfaceClosed(recess_box):
             print("Error: Recess cutout box is not closed!")
             rs.DeleteObjects([wedge_body, recess_box])
             return None
        print(f"Step 3: Phone recess cutout volume created (ID: {recess_box})")
    
        # 4. Create the Charging Cable Cutout Volume
        # Simple box positioned at the front-bottom-center
        cc_half_w = cable_cutout_width / 2.0
        cc_start_x = stand_base_depth - cable_cutout_depth_offset
        cc_end_x = stand_base_depth + 5 # Ensure it cuts through the lip fully
        cc_start_y = (stand_width / 2.0) - cc_half_w
        cc_end_y = (stand_width / 2.0) + cc_half_w
        cc_start_z = 0
        cc_end_z = cable_cutout_height
    
        cable_cutout_box = rs.AddBox([
            (cc_start_x, cc_start_y, cc_start_z), (cc_end_x, cc_start_y, cc_start_z),
            (cc_end_x, cc_end_y, cc_start_z), (cc_start_x, cc_end_y, cc_start_z),
            (cc_start_x, cc_start_y, cc_end_z), (cc_end_x, cc_start_y, cc_end_z),
            (cc_end_x, cc_end_y, cc_end_z), (cc_start_x, cc_end_y, cc_end_z)
        ])
    
        if not cable_cutout_box:
            print("Error: Failed to create cable cutout box.")
            rs.DeleteObjects([wedge_body, recess_box])
            return None
        if not rs.IsPolysurfaceClosed(cable_cutout_box):
             print("Error: Cable cutout box is not closed!")
             rs.DeleteObjects([wedge_body, recess_box, cable_cutout_box])
             return None
        print(f"Step 4: Cable cutout volume created (ID: {cable_cutout_box})")
    
    
        # 5. Perform Boolean Differences
        print("Performing boolean differences...")
    
        # Difference 1: Cut phone recess
        result1 = rs.BooleanDifference(wedge_body, recess_box, delete_input=False) # Keep inputs for debugging if needed
        if not result1 or len(result1) != 1 or not rs.IsPolysurfaceClosed(result1[0]):
            print("Error: Boolean difference for phone recess failed or result is not a single closed solid.")
            rs.DeleteObjects([wedge_body, recess_box, cable_cutout_box])
            if result1: rs.DeleteObjects(result1)
            return None
        intermediate_stand = result1[0]
        rs.DeleteObject(wedge_body) # Delete original wedge
        rs.DeleteObject(recess_box) # Delete cutter
        print("Step 5a: Phone recess cut successfully.")
    
        # Difference 2: Cut cable slot
        final_stand_list = rs.BooleanDifference(intermediate_stand, cable_cutout_box, delete_input=True) # Delete intermediate and cutter
        rs.DeleteObject(cable_cutout_box) # Make sure cable box is deleted even if boolean fails slightly
    
        if not final_stand_list or len(final_stand_list) != 1:
            print(f"Error: Boolean difference for cable cutout failed or resulted in multiple objects ({len(final_stand_list) if final_stand_list else 0}).")
            # Don't delete intermediate_stand here, maybe it's useful for debugging
            if final_stand_list: rs.DeleteObjects(final_stand_list)
            rs.SelectObject(intermediate_stand) # Select the state before the failed boolean
            print("Selected the object state BEFORE the failed cable cutout boolean.")
            return None # Indicate failure but leave the intermediate object
    
        final_stand = final_stand_list[0]
    
        # Final Check for Closed Polysurface
        if not rs.IsPolysurfaceClosed(final_stand):
            print("CRITICAL Error: The final object is NOT a closed polysurface after booleans!")
            # Don't delete the object, let the user inspect it
            rs.SelectObject(final_stand)
            return None # Indicate failure
        else:
            print("Step 5b: Cable cutout successful. Final object is a closed polysurface.")
    
    
        # --- Cleanup and Finish ---
        rs.SelectObject(final_stand)
        rs.ZoomSelected()
        print(f"Phone stand creation complete! Final Object ID: {final_stand}")
        return final_stand
    
    # --- Run the function ---
    if __name__ == "__main__":
        # Ensure Rhino environment is active
        if rs.IsRhino():
            # Clear selection before running
            rs.UnselectAllObjects()
            # Execute the creation function
            created_stand_id = create_solid_phone_stand()
    
            if created_stand_id:
                print("\n--- Ready to Export ---")
                print("Select the generated object.")
                print("Go to File > Export Selected...")
                print("Choose STL (Stereolithography) as the file type.")
                print("Use Binary format and adjust mesh settings if needed for your 3D printer.")
            else:
                print("\n--- Stand Creation Failed ---")
                print("Review the error messages in the console.")
                print("Check intermediate geometry if it wasn't deleted.")
    
        else:
            print("This script must be run inside the Rhino Python editor.")
    
    

    How it Addresses the "Closed Surface" Requirement:

    1. Starts with Solids: It begins with rs.AddBox, which creates guaranteed closed polysurfaces.
    2. Solid Operations: It primarily uses rs.SplitBrep (with a plane, which typically results in closed pieces if the input is closed) and rs.BooleanDifference. Boolean operations are designed to maintain closure if the inputs are closed and intersect cleanly.
    3. Intermediate Checks: The script includes checks using rs.IsPolysurfaceClosed() after major steps (initial block creation, splitting, final result). This helps catch errors early.
    4. Robust Cutters: The cutout volumes (recess_box, cable_cutout_box) are also created as simple closed boxes, improving the reliability of the boolean operations.
    5. Error Handling: The script checks the return values of boolean operations. A successful difference resulting in one object should return a list containing exactly one ID. If it returns None, an empty list, or a list with multiple IDs, it indicates a problem (e.g., no intersection, tangential intersection, non-manifold result). The script tries to report these errors.

    To Use:

    1. Open Rhino.
    2. Go to Tools > PythonScript > Edit...
    3. Paste the entire script into the editor.
    4. Modify the parameters under the --- Parameters --- section as needed for your phone size and preferences.
    5. Run the script (click the green play button or press F5).
    6. Check the Rhino command line/history window for messages (especially errors).
    7. If successful, the final phone stand object will be created and selected. Export it as an STL file for printing.

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.