Skip to content

AssertionError: curve and relativeCurve must have the same length #14

@rahulbknowbe4

Description

@rahulbknowbe4

Getting the below error

AssertionError: curve and relativeCurve must have the same length

The sample script

from shapesimilarity import shape_similarity
import matplotlib.pyplot as plt
import numpy as np

# Circle
theta = np.linspace(0, 2*np.pi, 100)
radius = 1
circle_x = radius * np.cos(theta)
circle_y = radius * np.sin(theta)
circle = np.column_stack((circle_x, circle_y))

# Rectangle
rect_x = np.array([1, 1, -1, -1, 1])  # Add the first point again to close the shape
rect_y = np.array([0.5, -0.5, -0.5, 0.5, 0.5])
rectangle = np.column_stack((rect_x, rect_y))

# Oval (Ellipse)
a, b = 1.5, 0.75  # Semi-major and semi-minor axes
oval_x = a * np.cos(theta)
oval_y = b * np.sin(theta)
oval = np.column_stack((oval_x, oval_y))

# Square
square_x = np.array([1, 1, -1, -1, 1])  # Add the first point again to close the shape
square_y = np.array([1, -1, -1, 1, 1])
square = np.column_stack((square_x, square_y))

# Pentagon
pentagon_radius = 1
pentagon_angles = np.linspace(0, 2*np.pi, 6)[:-1]  # 5 points, exclude the last duplicate
pentagon_x = pentagon_radius * np.cos(pentagon_angles)
pentagon_y = pentagon_radius * np.sin(pentagon_angles)
# Add first point to close the shape
pentagon_x = np.append(pentagon_x, pentagon_x[0])
pentagon_y = np.append(pentagon_y, pentagon_y[0])
pentagon = np.column_stack((pentagon_x, pentagon_y))


shape1 = circle
shape2 = rectangle

similarity = shape_similarity(shape1, shape2)

plt.plot(shape1[:,0], shape1[:,1], linewidth=2.0)
plt.plot(shape2[:,0], shape2[:,1], linewidth=2.0)

plt.title(f'Shape similarity is: {similarity}', fontsize=14, fontweight='bold')
plt.show()

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions