How to create a tangent line in a single curve

I have a single curve (white) and I would like to create a tangent line as black in C++
Help me

Hi Luciano,
You must adjust the length but there you go

import Rhino
import scriptcontext
import rhinoscriptsyntax as rs

def create_tangent_line():
    curve_id = rs.GetObject("Select a curve", rs.filter.curve)
    if not curve_id: return
    point_on_curve = rs.GetPointOnCurve(curve_id, "Pick a point on the curve for the tangent")
    if not point_on_curve: return
    curve = rs.coercecurve(curve_id)
    if not curve: return
    param = curve.ClosestPoint(point_on_curve)[1]
    tangent = curve.TangentAt(param)
    if not tangent: return
    tangent_length = 100
    start_point = point_on_curve
    end_point = rs.PointAdd(point_on_curve, tangent * tangent_length)
    # Add the tangent line to the document
    tangent_line_id = rs.AddLine(start_point, end_point)
    if tangent_line_id:
        print("Tangent line added to the document.")

in RhinoCommon there is
not sure what the underlaying c++ funciton is

If I divide this curve in half, could I use this option to create the tangent line between the curves?

Has anyone used this option??

bool TryCreateBetweenCurves(ON_Curve* curva0, ON_Curve* curva1, double t0, double t1, bool perpendicular0, bool perpendicular1, ON_Line* linha);

Thanks (9.5 KB)

dear @Luciano_Luiz_da_Silv

    double t0,t1;
    if ( ! crv.ClosestPoint(p0,out t0) || !crv.ClosestPoint(p1,out t1))
    Line li;
    if (Line.TryCreateBetweenCurves(crv,crv,ref t0, ref t1,false,false, out li))
        a = li;

see attached script (in grasshopper)
you can pass the same curve twice. - with 2 different parameters close to where you expect the tangent-tangent line.

A good starting point for the 2 Points that are close to the curve might be a convex hull.

Hi Tom_P

I need to use in C++…

yes i know, but did you test passing the same curve in c++ twice and 2 parameters ? - as far as I understand Rhinocommon calls those underlaying C++ functionality - so it should not behave to much different.

EDIT … i might be wrong… not sure at which technology-layer TryCreateBetweenCurves is implemented.
@Dale is the right person to ask I think.

in some older (Rhino 5) sourcecode you can see that Rhinocommon calls some RHC_RhGetTanPerpPoint - maybe this helps for your search ?

Hi @Luciano_Luiz_da_Silv,

The function behind TryCreateBetweenCurves is not exposed to the C++ SDK. I’ve logged an issue so we can fix.


– Dale