views:

963

answers:

4

I have an array of mouse points, a stroke width, and a softness. I can draw soft circles and soft lines. Which algorithm should I use for drawing my array of points? I want crossed lines to look nice as well as end points.

+1  A: 

I think maybe you're looking for a spline algorithm.

Here is a spline tutorial, which you might find helpfull:

[http://www.doc.ic.ac.uk/~dfg/AndysSplineTutorial/index.html]

The subject is also covered in most books on graphics programming.

Cheers.

tovare
+2  A: 

I would definitely choose the Bezier for that purpose, and in particular I will implement the piecewise cubic Bezier - it is truly easy to implement and grasp and it is widely used by 3D Studio max and Photoshop.

Here is a good source for it: http://local.wasp.uwa.edu.au/~pbourke/surfaces_curves/bezier/cubicbezier.html

Assuming that you have an order between the points, in order to set the four control points you should go as follows:

I define the tangent between point P[i] and point P[i+1]

  • T1 = (P[i+1] - P[i-1])
  • T2 = (P[i+2] - P[i])

And to create the piecewise between two points I do the following:

  • Control Point Q1: P[i]
  • Control Point Q2: the point lying along the tangent from Q1 => Q1 + 0.3T1
  • Control Point Q3: the point lying along the tangent to Q4 => Q4 - 0.3T2
  • Control Point Q4: P[i+1]

The reason I chose 0.3T is arbitrary in order to give it enough 'strength' but not too much, you can use more elaborated methods that will take care of acceleration (C2 continuity) as well.

Enjoy

Adi
A: 

I figured it out - use a very soft gradient circle, draw repeatedly to make a stroke, blend using multiply.

Brian
+1  A: 

Starting from Gooch & Gooch's Non-Photorealistic Rendering, you might find Pham's work useful - see PDF explaining algorithm.

There's a nice overview article by Tateosian which explains the additional techniques in less detail with pretty pictures.Bezier curve drawing alone doesn't produce the effects you want (depending on how fancy you want to get). However, I'd certainly start with Paul's work and see if just using that to draw with your soft brush is good enough.

Be warned there are lots of patents in this space, sigh.

Andy Dent
Excellent links! The review article is particularly interesting.
Ranieri