Circles


Geometric definition


A Circle is a closed curve for which all the points are in the same plane and at a given distance from a center. (Think of how we can draw a circle on a sheet of paper)

Therefore, in 2D we only need a center and a radius, but in 3D, we also need to know the plane in which the circle is situated.

How to add


Rhinocommon


import scriptcontext as sc
import Rhino

# Will create a circle of radius 5 in the XY plane and with (0, 0, 0) as origin
my_circle = Rhino.Geometry.Circle(5)

sc.doc.Objects.AddCircle(my_circle)


import scriptcontext as sc
import Rhino

# 3 initial points
point_A = Rhino.Geometry.Point3d(0, 0, 0)
point_B = Rhino.Geometry.Point3d(1, 1, 1)
point_C = Rhino.Geometry.Point3d(1, 0, 1)

# Will create a circle passing by 3 points
my_circle = Rhino.Geometry.Circle(point_A, point_B, point_C)

sc.doc.Objects.AddCircle(Second_circle)


import scriptcontext as sc
import Rhino

# Initial parameters to create the circle
point_A = Rhino.Geometry.Point3d(1, 0, 1)
plane = Rhino.Geometry.Plane(1, 0, 0, 10)
radius = 5

# Will create a circle parallel to the plane, with p1 as origin and of radius 5
my_circle = Rhino.Geometry.Circle(plane, point_A, radius)

sc.doc.Objects.AddCircle(my_circle)


import scriptcontext as sc
import Rhino

# Points that will be used to create the circle
point_B = Rhino.Geometry.Point3d(1, 0, 0)
point_C = Rhino.Geometry.Point3d(2, 2, 0)
point_D = Rhino.Geometry.Point3d(2, -1 ,0)
points = [point_A, point_B, point_C, point_D]

# Will calculate the best fitting circle trough a set of points
res, my_circle = Rhino.Geometry.Circle.TryFitCircleToPoints(points)


import scriptcontext as sc
import Rhino

# lines to which a tangent circle will be calculated
line_1 = Rhino.Geometry.Line(point_A, point_B)
line_2 = Rhino.Geometry.Line(point_A, point_C)
lenght_parameter_1 = 1.5
length_parameter_2 = 1.2

# Will calculate the tangent circle to two curves at two given points. 
# ! Such a circle doesn't always exist, in which case it only takes the two tangents and the first point, discarding the second point.
my_circle = Rhino.Geometry.Circle.TryFitCircleTT(l1, l2, length_parameter_1 , length_parameter_2)

Rhinocriptsyntax


import rhinoscriptsyntax as rs

# Parameters to create the circle
my_plane = rs.WorldZXPlane()
radius = 4

# Will create and add a plane to the Rhino workspace, given a base plane and a radius
rs.AddCircle(my_plane, radius)

Main methods and properties


Method


point_A = Rhino.Geometry.Point3d(0, 0, 0)

# Will calculate the closest point to " my_point" on the circle:
closest_point = my_circle.ClosestPoint(point_A)

Properties


Among the main properties, we have:

# Will retrieve the normal to the circle at its center
circle_normal = my_circle.Normal

# Will retrieve the center of the circle
circle_center = my_circle.Center

# Will retrieve the circle's diameter
circle_diam = my_circle.Diameter

# Will calculate the circle's circumference
circle_circum = my_circle.Circumference


🛠 Exercises


01: 🐍⬇️⬇️⬇️ Download the script here ⬇️⬇️⬇️🐍 02: 🐍⬇️⬇️⬇️ Download the script here ⬇️⬇️⬇️🐍

Solution:

01: 🐍⬇️⬇️⬇️ Download the script here ⬇️⬇️⬇️🐍 02: 🐍⬇️⬇️⬇️ Download the script here ⬇️⬇️⬇️🐍