Home Forums Nazca Bezier Curves with arbitrary number of points

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #6376
    mpapadov
    Participant

    Hello Nazca Team,

    I am trying to construct an S Bend based on Bezier curves with 4 control points.

    So far I have used the parametric curve method through the viper method as follows:

    import nazca as nd
    
    def x(t, x_S, **kwargs):
        """X as function of t and free parameters."""
        return (1-t**3)*0 + 3*(1-t)**2*t*x_S/2 + 3*(1-t)*t**2*x_S/2 + t**3*x_S
    
    def y(t, y_S, **kwargs):
        """Y as function of t and free parameters."""
        return (1-t**3)*0 + 3*(1-t)**2*t*0 + 3*(1-t)*t**2*y_S + t**3*y_S
    
    def w(t, width=None, **kwargs):
        """Width (constant)."""
        return width
    
    # create the new parametric function using the template Tp_viper():
    params = {'x_S':8, 'y_S':1.05, 'width':0.3}
    S_bend_bot = nd.Tp_viper(x, y, w, **params, name='S_Bend_Bottom')
    
    S_bend_bot(width1=2.0).put(0)
    
    nd.export_plt()

    This design utilizes the parametric equations for Bezier curves (wiki page), and it works great, however there are tiny discontinuities at the input and output points of the curve as it consists of a finite number of N segments.

    In my case the Bezier curve consists of 4 points.

    My question is whether there exists a function in Nazca that takes these 4 control points (poles) as input and gives the corresponding Bezier curve as output, similarly to this example from Lumerical:

    Thank you in advance for your help.

    Marios

    #6378
    Ronald
    Keymaster

    Dear Marios,

    The discretization may indeed lead to small polygon issues at the start and end points of a curve, as these angles are not exact when based in the last two points near an edge, if there is a curvature.

    This deviation can be avoided by providing the exact “input” and “output” angles of a curve. In the case of the Tp_viper() these should be optionally provided through keywords anglei and angleo, for the “input” and “output” of the curve, but these are not yet in the Viper keywords. I will add them (now always calculated inside the function before calling a deeper polygon function). Another way to improve the angle is to add a smaller last step in the Viper angle calculation, though this may suffer from numerical noise at some point. Yet another way is to extrapolate the curvature trend near the end an extrapolate that to the end point.

    Ronald

    PS
    Because you seem to have an input and output in the x-direction, you would simply have anglei=180, angleo=0 in your case.

    #6381
    mpapadov
    Participant

    Hi Ronald,

    Thank you very much for your prompt response. Indeed these input/output angles would completely solve my problem.

    If I understood correctly, the right way to do it would be:

    S_bend_bot = rx.Tp_viper(x, y, w, anglei=180, angleo=0, **params, name='S_Bend_Bottom')

    Or is it correct to add it when calling the function itself in the script?

    Kindly let me know which this is the right way to implement.

    Thank you in advance for all your help.

    Marios

    #6383
    Ronald
    Keymaster

    Dear Marios,

    Yes that will work, but as mentioned it needs the anglei and angleo keywords to be added to the Tp_Viper internally, which will now be in the new Nazca release (>0.5.12).

    For your information, the Viper internally only needs an override when angles are provided, like below. Angle “ab” carries through to a deeper polygon routine.

    if angleo is None:    
       ab = degrees(atan2( Y(1)-Y(1-d), X(1)-X(1-d)))  # angle of last semgent
    else:   
       ab = angleo

    Ronald

    #6384
    mpapadov
    Participant

    Dear Ronald,

    I understand what you mean now.

    Thank you for all the information and looking forward to the new version!

    Marios

Viewing 5 posts - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.