Description
Tester une forme pour vérifier s’il s’agit d’un vrai rectangle.
Le script suivant fonctionne sur :
- Rhino pour Windows ;
- Rhino pour macOS.
Script par MLAV.LAND, sous licence GNU GPL 3.
Code
import rhinoscriptsyntax as rs
def is_rectangle():
# Select a closed curve composed of 4 points (a quad)
curve = rs.GetObject("Select a closed curve composed of 4 points", rs.filter.curve)
if not curve:
print("No valid curve selected.")
return
# Check if the curve is a closed curve composed of exactly 4 points
if not rs.IsPolyline(curve) or len(rs.PolylineVertices(curve)) != 5:
print("The selected curve is not a valid quad.")
return
# Get the four corner points of the quad
points = rs.PolylineVertices(curve)
# Calculate the diagonal lengths
diagonal1 = rs.Distance(points[0], points[2])
diagonal2 = rs.Distance(points[1], points[3])
# Check if the diagonal lengths are approximately equal
tolerance = 0.01 # Adjust the tolerance as needed
if abs(diagonal1 - diagonal2) < tolerance:
print("The selected shape is a true rectangle.")
else:
print("The selected shape is a random quad.")
if __name__ == "__main__":
is_rectangle()