Hi all, my goal is to compare the red and yellow geometry (tree branch shape) with the white design branch. I wanted to do this via GHpython, but that doesn’t seem to recognize the point coordinates in my panel. It says its a string, and that it requires it to be a point3D.
this is the error that I keep getting:
Runtime error (ArgumentTypeException): expected Point3d, got str
Traceback:
- line 24, in compare_forks, “”*
- line 37, in script*
is there a way I can let ghpython recognize these as actual points instead of strings.
the code I’m working with:
import Rhino.Geometry as rg
import math
# Function to calculate the angle between two vectors
def calculate_angle(vector1, vector2):
return rg.Vector3d.VectorAngle(vector1, vector2)
# Function to normalize the angle to a match score (0 = worst match, 1 = perfect match)
def normalize_angle_to_match_score(angle):
return 1 - (angle / math.pi) # Normalizes angle to a score between 0 and 1
# Inputs from Grasshopper (connected directly to the script)
# Tree forks and design forks as lists of Point3d
# tree_forks_1, tree_forks_2, and design_forks are already connected in Grasshopper
# tree_forks_1 = [list of 3 points representing tree fork 1]
# tree_forks_2 = [list of 3 points representing tree fork 2]
# design_forks = [list of 3 points representing the design fork]
# Function to compare each tree fork to the design fork and get the matching scores
def compare_forks(tree_forks, design_forks):
matching_scores = []
for i in range(len(tree_forks)):
tree_vector = rg.Vector3d(tree_forks[i]) # Vector from origin to tree fork endpoint
design_vector = rg.Vector3d(design_forks[i]) # Vector from origin to design fork endpoint
# Calculate the angle between the vectors
angle = calculate_angle(tree_vector, design_vector)
# Convert the angle to a match score (0 = worst match, 1 = perfect match)
match_score = normalize_angle_to_match_score(angle)
matching_scores.append(match_score)
return matching_scores
# Compare the first tree fork (tree_forks_1) with the design fork
matching_scores_1 = compare_forks(tree_forks_1, design_forks)
# Compare the second tree fork (tree_forks_2) with the design fork
matching_scores_2 = compare_forks(tree_forks_2, design_forks)
# Average match score for each tree fork
avg_match_score_1 = sum(matching_scores_1) / len(matching_scores_1)
avg_match_score_2 = sum(matching_scores_2) / len(matching_scores_2)
# Output the match scores for each tree fork
a = avg_match_score_1 # Match score for tree_forks_1
b = avg_match_score_2 # Match score for tree_forks_2