Exploring the Magic and Limitations of ChatGPT in Generating Python Code for Acoustic Design

Exploring the Magic and Limitations of ChatGPT in Generating Python Code for Acoustic Design

On the internet, ChatGPT is hailed as a coding wizard, capable of conjuring up web pages from mere sketches and crafting apps in a single day. But how does ChatGPT fare when it comes to generating Python code for acoustic design in Grasshopper? I put both GPT3.5 and GPT4 to the test, and while they were able to quickly convert prompts into clean code, more often than not, the resulting code failed to run properly. Asking ChatGPT to debug its own code proved to be a fruitless endeavor.

That being said, ChatGPT did manage to produce an impressive Python code for representing an omni directional sound source. When using rays to represent such a source, the end points of each ray on the radiation sphere should be evenly spaced. This seemingly simple requirement is actually a fascinating mathematical problem, as it turns out that for more than 20 points on a sphere, it is impossible to achieve perfect evenness. However, mathematicians have devised several methods to achieve the most even distribution possible.

Using the Fibonacci spiral method, ChatGPT submitted a well-executed solution, as shown below.

import rhinoscriptsyntax as rs

import math

def create_sphere_points(center, radius, num_points):

  phi = math.pi * (3 - math.sqrt(5)) # golden angle in radians

  points = []

  for i in range(num_points):

    y = 1 - (i / float(num_points - 1)) * 2 # y goes from 1 to -1

    radius_at_y = math.sqrt(1 - y * y) # radius at y

    theta = phi * i # golden angle increment

    x = math.cos(theta) * radius_at_y

    z = math.sin(theta) * radius_at_y

    point = [x * radius, y * radius, z * radius]

    point = rs.PointAdd(center,point)

    points.append(rs.AddPoint(point))


  # Create a list to store the vectors

  vectors = []


  # Create a vector from the center to each point

  for point in points:

    vector = rs.VectorCreate(point, center)

    vectors.append(vector)

  # Return the list of vectors and points

  return vectors, points


# Call the create_sphere_points function with the input parameters

vectors,points = create_sphere_points(center, radius, num_points)


# Add the sphere and points to the Rhino document

sphere = rs.AddSphere(center, radius)

To view or add a comment, sign in

Others also viewed

Explore content categories