Bug 710 : bezierTangent() formula appears incorrect
Last modified: 2008-04-11 20:08




Status:
RESOLVED
Resolution:
FIXED -
Priority:
P2
Severity:
normal

 

Reporter:
davbol
Assigned To:
fry

Attachment Type Created Size Actions
diff patch 2008-01-07 14:26 339 bytes

Description:   Opened: 2008-01-07 14:02
As of 0135 beta, but probably much older... The equation currently in bezierTangent
() appears incorrect, and not equiv to first deriv of bezier eq itself, so doesn't
produce correct result for general cases. Here's the tangent example, changing the
second control coordinate from 90,90 to 120,120 to highlight the problem (at 90,90
the problem is disguised)

stroke(0);
noFill();
bezier(85, 20, 10, 10, 120, 120, 15, 80);
stroke(255, 102, 0);
int steps = 16;
for (int i = 0; i <= steps; i++) {
float t = i / float(steps);
float x = bezierPoint(85, 10, 120, 15, t);
float y = bezierPoint(20, 10, 120, 80, t);
float tx = bezierTangent(85, 10, 120, 15, t);
float ty = bezierTangent(20, 10, 120, 80, t);
float a = atan2(ty, tx);
a += PI/2.0;
line(x, y, cos(a)*8 + x, sin(a)*8 + y);
}



The tangent equation should be equiv to:

(-3t^2+6t-3)a + (9t^2-12t)b + (-9t^2+6t)c + (3t^2)d

though I think the t-factoring might be more efficient in code:

3t^2(-a+3b-3c+d) + 6t(a-2b+c) + 3(-a+b)

...and of course there's probably a better factoring than that too, but i haven't looked
for it. ;)


ref: http://processing.org/discourse/yabb_beta/YaBB.cgi?
board=Programs;action=display;num=1199707324

ref: http://processing.org/discourse/yabb_beta/YaBB.cgi?
board=Programs;action=display;num=1176823261;start=1#1
Additional Comment #1 From davbol 2008-01-07 14:26
edit]
diff

Here's one possible implementation (note that handedness is reversed from prior
implementation, so to get demo to work as before you'd need -=PI/2 not +=PI/2
when turning tangent into normal)
Additional Comment #2 From fry 2008-01-15 21:20
cool, thanks a ton. now integrated for 0136.

i'm baffled as to what happened with that though--your code is nearly
identical to what i had there in an ancient release, then replaced it with
the code that you saw because it was having trouble. oh well, no time to
track it down.
Additional Comment #3 From fry 2008-04-11 20:08
*** Bug 756 has been marked as a duplicate of this bug. ***