Jump to content

# Bezier curves accuracy in VW...

## Recommended Posts

This as been bugging me for a while...

Since we don't have access to the "trim" command from VS, but I do need to split polylines at any point of they path a custom procedure was needed... but for some reason the results, even if good are not perfect!

The base of the work is the De Casteljau's Algorithm (here is some info about: http://ironbark.bendigo.latrobe.edu.au/~fran/int32gp/2004/wk13/lctr26.html).

At the first place I was thinking the problem lay on the inherent accuracy of a single point float value, but the algorithm work beautifully 2^x numbers (if you use the script at i:=4 or i:=8), but not so well with anything else (i:=3 and zoom in quite a bit to see the inaccuracies). At values like i:=12 you can see locus in the curve and others slightly out of it.

The Algorithm is suppose to work for any factor, and I'm wondering why we get this inaccuracies?

A bit of trigo on the De Casteljau's enable to cut a polyline at any selected point along a bezier curve, and there is no need for much more code to do so, but at the moment the results show the same pattern of inaccuracies than the algorithm.

I hope anyone has any input on the subject, or can come up with the algorithm VW use to define bezier curves. I'm trying to develop the same functions using NSBezier (cocoa) to see if is any better.

-The script only works on 3 vertex bezier polyline. I recommend to draw a 2 sided polygon, duplicate and smooth by bezier spline. Then you can run the script selecting the polygon's 3 vertex. I keep the input as 3 points to experiment on different orders or configurations

code:

`Procedure  De_Casteljaus;`

{debug}

VAR

x,y,a1,a2,d1,d2,a3,d3: REAL;

h: HANDLE;

s: STRING;

i,j: INTEGER;

o,u: BOOLEAN;

P1,P2,P3,p4,p5,p6: POINT;

BEGIN

{Select polyline first point, the bezier point, then the last point}

{} GetPt(P1.x,P1.y);

{} GetPt(P2.x,P2.y);

{} GetPt(P3.x,P3.y);

{Poly sides angles calculations}

IF ((P2.x-P1.x))>0 THEN a1:=Arctan( (P2.y-P1.y)/(P2.x-P1.x) )

ELSE a1:=Arctan( (P2.y-P1.y)/(P2.x-P1.x) )+ Deg2Rad(180);

IF ((P3.x-P2.x))>0 THEN a2:=Arctan( (P3.y-P2.y)/(P3.x-P2.x) )

ELSE a2:=Arctan( (P3.y-P2.y)/(P3.x-P2.x) )+ Deg2Rad(180);

{Poly sides distances calculations}

d1:= Sqrt( Sqr(P2.x-P1.x)+Sqr(P2.y-P1.y));

d2:= Sqrt( Sqr(P3.x-P2.x)+Sqr(P3.y-P2.y));

i:=4; {number of subdvisions}

FOR j:=1 TO (i-1) DO BEGIN

{New points P4 P5 along the sides}

P4.x:= P1.x+(Cos(a1)*d1/i*j);

P4.y:= P1.y+(Sin(a1)*d1/i*j);

P5.x:= P2.x+(Cos(a2)*d2/i*j);

P5.y:= P2.y+(Sin(a2)*d2/i*j);

IF ((P5.x-P4.x))>0 THEN a3:=Arctan( (P5.y-P4.y)/(P5.x-P4.x) )

ELSE a3:=Arctan( (P5.y-P4.y)/(P5.x-P4.x) )+ Deg2Rad(180);

d3:= Sqrt( Sqr(P5.x-P4.x)+Sqr(P5.y-P4.y));

{New point P6 on the polylines calculation}

P6.x:= P4.x+(Cos(a3)*d3/i*j);

P6.y:= P4.y+(Sin(a3)*d3/i*j);

Locus(p6.x,p6.y);

END;

END;

RUN (De_Casteljaus);

[/code]

## Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Restore formatting

Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×

• KBASE
• #### MARIONETTE

×
• Create New...