# Closest Point on Curve to Axis

Developer: RhinoScript
Summary: Demonstrates how to find the closest point on a planar curve to an axis.

## Question

I have a bunch of 2-D curves that are planar to the world x-y plane, and I need to find a point in each curve that is closest to the world y-axis. For example:

What can I do to calculate this point?

After selecting the curves and verifying that they are both planar and line in the world x-y plane, calculate the world axis-aligned bounding box for each curve. Using the results of the bounding box calculation, create a line, using the first two points from the results, that is parallel to the world y-axis. Intersect this line with the curve. The results of the intersection will be at the point that is closest to the world y-axis.

## Example

The following example demonstrates the above algorithm:

Option Explicit

Sub ClosestAxisPoint

Dim arrCurves
arrCurves = Rhino.GetObjects("Select planar curves", 4, True, True)
If Not IsArray(arrCurves) Then Exit Sub

Dim strCurve, arrPlane(3), arrBox, strLine, arrCCX
arrPlane(0) = Array(0,0,0)
arrPlane(1) = Array(1,0,0)
arrPlane(2) = Array(0,1,0)
arrPlane(3) = Array(0,0,1)

Rhino.EnableRedraw False

For Each strCurve In arrCurves
If Rhino.IsCurvePlanar(strCurve) Then
If Rhino.IsCurveInPlane(strCurve, arrPlane) Then
arrBox = Rhino.BoundingBox(strCurve)
arrCCX = Rhino.CurveCurveIntersection(strCurve, strLine)
If IsArray(arrCCX) Then
End If
Rhino.DeleteObject strLine
End If
End If
Next

Rhino.EnableRedraw True

End Sub