Tagged: polygons, viper, parametric curves, Sbend, Bezier
 This topic has 4 replies, 2 voices, and was last updated 2 years, 11 months ago by mpapadov.

AuthorPosts

19 March 2021 at 09:55 #6376mpapadovParticipant
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 (1t**3)*0 + 3*(1t)**2*t*x_S/2 + 3*(1t)*t**2*x_S/2 + t**3*x_S def y(t, y_S, **kwargs): """Y as function of t and free parameters.""" return (1t**3)*0 + 3*(1t)**2*t*0 + 3*(1t)*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
19 March 2021 at 10:33 #6378RonaldKeymasterDear 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
andangleo
, 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 xdirection, you would simply haveanglei=180, angleo=0
in your case.19 March 2021 at 19:09 #6381mpapadovParticipantHi 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
20 March 2021 at 12:24 #6383RonaldKeymasterDear 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(1d), X(1)X(1d))) # angle of last semgent else: ab = angleo
Ronald
22 March 2021 at 09:53 #6384mpapadovParticipantDear Ronald,
I understand what you mean now.
Thank you for all the information and looking forward to the new version!
Marios

AuthorPosts
 You must be logged in to reply to this topic.