Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Bezier Splines
Message
De
24/02/2006 06:03:50
 
 
À
23/02/2006 17:02:22
Information générale
Forum:
Windows
Catégorie:
Informatique en général
Titre:
Divers
Thread ID:
01098145
Message ID:
01098817
Vues:
18
Hi,

>Nice link on how Beziers work!
>
>This looks like one of those cases where if you could do it with pencil and paper it would be dead easy :)
>
>1. Draw your Bezier spline
>2. Select a start point for your character
>3. Set the span of a pair of compasses equal to the baseline width of the character
>4. Stick the pin of the compasses at your start point
>5. Where the arc of the compass intersects the Bezier, that's the other end of your required secant
>
>On first blush the math to get an exact answer looks fairly hideous. Referring to the first link I gave you, it looks like Beziers are typically defined such that x and y are separate functions (cubic polynomials) of a third parameter, t. Deriving y = F(x) from this probably requires:
>
>1. Solving a cubic equation so that you get t = G(x) ( http://mathworld.wolfram.com/CubicFormula.html )
>2. Plugging that equation for t into the cubic polynomial that defines y.
>
>But even then, you're not finished. You now need to plug that into the formula that determines the (straight-line) distance between two points and solve that for the case where the required distance equals your desired baseline width.
>
>Of course, since there's such a simple paper exercise that solves this there may be an equally elegant mathematical technique, but I have NO idea what it might be.
>
>Seeing as we're talking about computers you might be able to use a numerical approximation:
>
>1. Set a start value of t (t1)
>2. Calculating x1 and y1 are dead easy
>3. Guess another value of t (t2)
>4. Calculate x2 and y2
>5. See how far apart (x1, y1) and (x2, y2) are (the secant length).
>6. Repeat 3 through 5, modifying your guesses for t until the secant length is "close enough".
>
>Good luck!

Thanks for the thoughts. I think the pure math solution is going to be too much for me. As you say the 'pen and paper' solution is easy - but it is, of course, in effect trial and error since you're testing points along the arc described by the compass. Anyway I'm got a couple of approaches to try:

(a) Calculate successive pixel positions by plotting my own bezier curve. When I hit one the required distance from the start point I've got my end point. (This is the same as your suggestion for an approximation approach)

(b) (the lazy way) Create the curve as a Graphics path in .NET then loop through an arc of possible end points relying on GraphicsPath.IsOutlineVisible() to find the intersection. This pretty much mimics the 'pen and paper' solution

Both are basically trial and error and both capable of some optimisation. Problem with (a) is that if my algorthym for plotting the curve is not idenitical to .NET's then I could get an accumulating error.
Problem with (b) is that my pixel sequence might transect the curve without getting a hit.

If nothing else suggests itself, or is suggested, I'll start experimenting with these.
Regards,
Viv
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform