Surprisingly, I’m seeing morе аnd morе traffic to mу “Inheritance іn JavaScript” tutorial. Αs thаt traffic hаs increased, thеre hаve bеen a number of legitimate complaints аbout mу uѕe of аn “іnit” method to initialize bаse classes аnd ϲhild classes. I found a wаy around thаt lаst October, ѕo I thought іt wаs hіgh tіme to incorporate thаt approach іnto thе tutorial. Ѕo, іf уou fіnd C#/Јava-ѕtyle ΟOP іn JavaScript interesting (or аt lеast not offensive), thеn уou mаy еnjoy mу latest updated tutorial.
http://www.kevlindev.ϲom/tutorials/javascript/inheritance/іndex.htm
Special thanks go to Robіn Debreuil - аka. Τhe Prototype Master - for suggesting how to gеt around thе uѕe of “іnit”. Αlso, special thanks to Ρeter Michaux (аnd mаny others) for gently prodding mе to update mу tutorial.
I am pleased to notice that other people promote a C#/Java-style OOP in JavaScript (which indeed may be subject to discussion . For that reason, I enjoyed reading your tutorial!
Last year, I have created a small shareware library around the concepts that you mention in your tutorial. If you are interested, you can download it at http://software.antrix.nl/
Jeroen
Kevin,
Thanks for replying. I’ve made an attempt at implementing your algorithm in Java (using double precision), see here:
http://boredgamer.org/BezierPain.java
It doesn’t work, though. I’ve been over and over your javascript and I can’t find the problem…
Dan
Hi Dan,
Thanks for the feedback! It’s been a long time since I wrote that intersection code, but I’ll see if I can remember the general idea. I’ll assume you’re refering to the various bezier-bezier intersections as opposed to say the bezier-line intersection.
First off, I got a huge amount of help from David Eberly. I’m using a fair amount of his algorithms for the actual root finding since they appear to work well in my limited usage of them. Also, he pointed me to an article called “Elimination and Resultants”. It was well worth the money buying that article.
So, basically the process is to convert the bezier from Berstein polynomials to their equivalent quadratic or cubic polynomials, one for each axis. From there, I find the Bezout determinant and solve for one of the unknowns. I plug each of the roots of that polynomial into the other unknown’s polynomial. Each value that gives me zero in both polynomials is an intersection. I tried to be pretty thorough with my comments in the quadraticBezier-quadraticBezier intersection. You may find that code helpful. See Intersection.intersectBezier2Bezier2 line 113.
One thing I should mention. Originally, I used MuPad and Mathematica to do all the math. That’s why you see all that ugliness in intersectBezier3Bezier3. I decided to make the code more readable by performing the steps explicitly in code like you see in intersectBezier2Bezier2. However, I must be getting underflows/overflows in the floating point which caused failures with the cubic beziers. Some day I’ll try to analyze the code to see how that can be remedied.
HTH,
Kevin
Kevin,
Your work is incredible. Still, I want to know, what method are you using to solve bezier intersections? I’m trying to do it myself and having a bad time.
Thanks very much
Dan
Sweet, thanks. You are still the man.