Object made out of tetrahedrons

Here’s a video demonstrating how my script works:

  • The tetrahedron that is being created is a pre-set block called “tetra”

Here’s the script itself:

# -*- coding: utf-8 -*-
import rhinoscriptsyntax as rs
import Rhino

def insert_tetra_block_precisely():
    pts = rs.GetPoints("Выберите 3 точки (A, B, C)", max_points=3)
    if not pts or len(pts) != 3:
        return

    A, B, C = pts
    O = [(A[i] + B[i] + C[i]) / 3.0 for i in range(3)]

    vecAB = rs.VectorCreate(B, A)
    vecAC = rs.VectorCreate(C, A)
    normal = rs.VectorCrossProduct(vecAB, vecAC)
    normal = rs.VectorUnitize(normal)

    y_vec = rs.VectorCreate(B, O)
    y_vec = rs.VectorUnitize(y_vec)

    perp_in_plane = rs.VectorCrossProduct(normal, y_vec)
    perp_in_plane = rs.VectorUnitize(perp_in_plane)

    ray_end = [O[i] + perp_in_plane[i] * 1000 for i in range(3)]
    intersection = rs.LineLineIntersection((O, ray_end), (B, C))
    if not intersection:
        return
    Q = intersection[0]

    x_vec = rs.VectorCreate(Q, O)
    x_vec = rs.VectorUnitize(x_vec)

    z_vec = rs.VectorCrossProduct(x_vec, y_vec)
    z_vec = rs.VectorUnitize(z_vec)

    y_vec = rs.VectorCrossProduct(z_vec, x_vec)
    y_vec = rs.VectorUnitize(y_vec)

    origin = Rhino.Geometry.Point3d(*O)
    plane = Rhino.Geometry.Plane(origin, x_vec, y_vec)

    xform = Rhino.Geometry.Transform.PlaneToPlane(
        Rhino.Geometry.Plane.WorldXY, plane)

    block_name = "tetra"
    if rs.IsBlock(block_name):
        rs.InsertBlock2(block_name, xform)

insert_tetra_block_precisely()

My goal is to upgrade the script and make it create a new tetrahedron based on surface, not on 3 points. On a video, you can see the problem when I select points counterclockwise: the new tetrahedron just flips inside another one. I’m still not sure how to control that, so the thing with worrking based on existing surface makes things harder.

How do I make script work using the surface-based creation? I was thinging about making it on pure math (calculating all of the new geometry based on the coordinates of selected triangle surface), but I need to work with blocks because later, when the structure is finished, the block will be replaced with a more complex tetrahedron-like model (it will have rods and more details)

Thanks in advance for anyone who gets interest in solving such a problem!

I don’t see a use in this script but that’s not my point.

Grasshopper has a component to transform objects from reference polygons to mesh faces. I thought this mesh based method would be quicker and more reliable than orienting from a triangular surface to another, since a surface is usually built of four points.

However, the definition creates an output with mesh normals facing inward which I currently don’t understand. Maybe @DanielPiker has an idea what’s wrong with my approach?

The idea would be to create a loop and to automate baking.

tetrahedrons chain.cs (1.5 KB)
executed as Rhino 8 c# script:

See similar code but in python here https://discourse.mcneel.com/t/python-preselected-mesh-face-or-edge/29839

2 Likes

I modified my definition so it pushes blocks and does not create copies :slight_smile:

tetrahedron-loop.gh (25.0 KB)
tetrahedron-loop.3dm (102.4 KB)

1 Like