Smooth a path

Hi all,

here is my ideal workflow for drawing a smooth path:

  1. Quickly specify ten-fifteen points through which my path will go. The points are joined by straight lines.

  2. Have a magic button that smooth out the pattern for me. I can push many times the button and the curve gets smoother and smoother.

I do not know whether the magic shortcut (or button) exists: at present I find myself fiddling with tangents, with irritating results.

Now, even though it may be argued that I am total disaster in understanding Bezier curves and how to smooth out a path using tangents, I think that an implementation of magic button 2) would be really a good improvement.

What is your workflow to draw smooth paths?

Best.
Daniele


Intaglio mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

On Mar 20, 2010, at 8:50 AM, Daniele Avitabile wrote:

Hi all,

here is my ideal workflow for drawing a smooth path:

  1. Quickly specify ten-fifteen points through which my path will
    go. The points are joined by straight lines.

  2. Have a magic button that smooth out the pattern for me. I can
    push many times the button and the curve gets smoother and smoother.

I do not know whether the magic shortcut (or button) exists: at
present I find myself fiddling with tangents, with irritating results.

Now, even though it may be argued that I am total disaster in
understanding Bezier curves and how to smooth out a path using
tangents, I think that an implementation of magic button 2) would
be really a good improvement.

I am afraid this has nothing to do with Bezier:

-- Draw a curve
-- Place ten-fifteen points on that curve.
-- Rotate everything a quarter turn or so.
-- Make the curve white so it becomes invisible.
-- Now get someone to draw a curve through the ten-fifteen points  

that remain visible
– Counter-rotate everything back
– Make the original curve visible again and compare the two curves.

In the case of an algorithm instead of “someone”, I think something
similar would still happen (*)

What is happening is that:

-- The smoothing algorithm must decide what tangents to use at the  

given points,
– That decision can be based only on what the algorithm is given,
namely the points,
– But there is an infinite number of curves going through any given
number of points and thus the tangents can be anything.
– So, the smoothing algorithms has to make assumptions such as, for
example:
If the slopes of the line between the first point and the second
point and the line between the second point and the third point have
opposite signs, then the tangent at the second point has slope 0.

But the necessary 0-slope point could be any point between the first
point and the third point and need not at all be the second point as
assumed. So, the algorithm would usually take the horizontal
distances between the points into account to decide where the 0-slope
point is. But that still remains an assumption.

And, indeed, such assumptions can work out to be widely unwarranted
(the reason for the rotation in the experiment).

In fact, it is well known that even plotting programs can err very,
very badly. (See http://www.dfanning.com/graphics_tips/lousysine.html
but Gilbert Strang’s “famous plot of the sine wave” shows that
aliasing is far from being the only thing that can happen.)

What is your workflow to draw smooth paths?

Completely ad hoc: Trying to anticipate which points will have
“influential” tangents.

Regards
–schremmer

(*) I don’t have one but, as I recall, Canvas’ smoothing algorithm
greatly irritated me.


Intaglio mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

Good point.

So let us say that a similar button could be implemented with a hand-drawn
path instead: it would still be much easier.

Best.
Daniele

On Sat, Mar 20, 2010 at 3:11 PM, Alain Schremmer
email@hiddenwrote:

On Mar 20, 2010, at 8:50 AM, Daniele Avitabile wrote:

Hi all,

here is my ideal workflow for drawing a smooth path:

  1. Quickly specify ten-fifteen points through which my path will go. The
    points are joined by straight lines.

  2. Have a magic button that smooth out the pattern for me. I can push many
    times the button and the curve gets smoother and smoother.

I do not know whether the magic shortcut (or button) exists: at present I
find myself fiddling with tangents, with irritating results.

Now, even though it may be argued that I am total disaster in
understanding Bezier curves and how to smooth out a path using tangents, I
think that an implementation of magic button 2) would be really a good
improvement.

I am afraid this has nothing to do with Bezier:

   -- Draw a curve
   -- Place ten-fifteen points on that curve.
   -- Rotate everything a quarter turn or so.
   -- Make the curve white so it becomes invisible.
   -- Now get someone to draw a curve through the ten-fifteen points

that remain visible
– Counter-rotate everything back
– Make the original curve visible again and compare the two curves.

In the case of an algorithm instead of “someone”, I think something similar
would still happen (*)

What is happening is that:

   -- The smoothing algorithm must decide what tangents to use at the

given points,
– That decision can be based only on what the algorithm is given,
namely the points,
– But there is an infinite number of curves going through any given
number of points and thus the tangents can be anything.
– So, the smoothing algorithms has to make assumptions such as, for
example:
If the slopes of the line between the first point and the
second point and the line between the second point and the third point have
opposite signs, then the tangent at the second point has slope 0.

But the necessary 0-slope point could be any point between the first point
and the third point and need not at all be the second point as assumed. So,
the algorithm would usually take the horizontal distances between the points
into account to decide where the 0-slope point is. But that still remains an
assumption.

And, indeed, such assumptions can work out to be widely unwarranted (the
reason for the rotation in the experiment).

In fact, it is well known that even plotting programs can err very, very
badly. (See http://www.dfanning.com/graphics_tips/lousysine.html but
Gilbert Strang’s “famous plot of the sine wave” shows that aliasing is far
from being the only thing that can happen.)

What is your workflow to draw smooth paths?

Completely ad hoc: Trying to anticipate which points will have
“influential” tangents.

Regards
–schremmer

(*) I don’t have one but, as I recall, Canvas’ smoothing algorithm greatly
irritated me.


Intaglio mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options


Intaglio mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

On Mar 20, 2010, at 1:36 PM, Daniele Avitabile wrote:

Good point.

So let us say that a similar button could be implemented with a
hand-drawn
path instead: it would still be much easier.

How would the program know an intentional bump from an accidental
one? What would prevent it from turning a human silhouette into a
circle? Here again, the program would have to make assumptions on the
“size” of the bumps to be smoothed out.

There are still things the human brain can do better than a program.

Regards
–schremmer


Intaglio mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

I just found out that Inkscape does it. It smoothes out a path iteratively.
And it does it well as far as I can tell. I guess it is not terrible to have
the software to make some reasonable assumptions for you, if you are still
given the chance to act on the tangents as you wish.

Furthermore, you can always type ctrl-z and go back to the previous path,
the one with “less degree of smoothness”, and edit the tangents as we do
now.

I don’t have an iPhone, therefore I can not try Intaglio for the iPhone, but
I guess this feature would be of interest in that case too.

I really don’t see why it would hurt to have the functionality and let the
user decide whether to use it or not.

Best.
Daniele


Intaglio mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

On Mar 20, 2010, at 2:30 PM, Daniele Avitabile wrote:

I just found out that Inkscape does it.

I had considered it but on Tiger, it needs X11.

It smoothes out a path iteratively.
And it does it well as far as I can tell. I guess it is not
terrible to have
the software to make some reasonable assumptions for you, if you
are still
given the chance to act on the tangents as you wish.

Of course.

Furthermore, you can always type ctrl-z and go back to the previous
path,
the one with “less degree of smoothness”, and edit the tangents as
we do
now.

That is nice. When I move to 10.5 I will give Inkscape another try.

I don’t have an iPhone, therefore I can not try Intaglio for the
iPhone, but
I guess this feature would be of interest in that case too.

I really don’t see why it would hurt to have the functionality and
let the
user decide whether to use it or not.

It would not hurt. I was just teasing you on this last.

Regards
–schremme


Intaglio mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

Here’s my two pence worth if it’s worth anything.

Quite a few years ago I wanted to smooth curves for pattern recognition purposes and as Allain has pointed out the idea of what constitutes an appropriate degree of smoothing is something that a particular human might know but a machine not. Since what I was engaged on was what was then thought of as “capturing human expertiese” I looked at what might be the criteria a human used when evaluating such a problem. One approach, indeed the approach I gave some consideration too (and as I noted later in the literature did others) was the idea of increasing the smoothing parameter, e.g. the width of the convolving window in stages and noting the parameter values at which peaks in the curve disappeared. Then idea then would be to use this notion to do whatever.

So in the present case, should one want to smooth a given curve but the degree of smoothing was a matter of human judgement one might, most simply, allow the user to increase the smoothing parameter(s) or to specify the number of peaks required in the curve. Presumably Inkscape uses something like this.

Notice that this suggestion ignores the difficulties of defining what constitutes a peak, e.g. in a wiggly spiral or in a wiggly labyrinthine line, but the idea of allowing the user to vary the smoothing parameter(s) is not technically difficult. This suggestion also ignores that smoothing is a flattening process so that should you for instance have drawn your peaks at particular places and hoped they would stay put after smoothing then they will not.

My own view, for what it’s worth tends to side with Allain’s pessimism/realism except in so far that let us say that Intaglio implements this user variable smoothing parameter and people find it useful in which case there’s nothing to argue about other than the degree of utility versus the time or cost of implementing the interface and associated mechanism. I think bezier curves with handles and the ability to move, add or delete the control points are pretty good and as with most things require a degree of skill to use effectively. Automation is good when you can specify exactly what it is that you want the machine to do. It is useless when your definition includes human psychology which is beyond our understanding.

Julius

On 20 Mar 2010, at 19:45, Alain Schremmer wrote:

On Mar 20, 2010, at 2:30 PM, Daniele Avitabile wrote:

I just found out that Inkscape does it.

I had considered it but on Tiger, it needs X11.

It smoothes out a path iteratively.
And it does it well as far as I can tell. I guess it is not terrible to have
the software to make some reasonable assumptions for you, if you are still
given the chance to act on the tangents as you wish.

Of course.

Furthermore, you can always type ctrl-z and go back to the previous path,
the one with “less degree of smoothness”, and edit the tangents as we do
now.

That is nice. When I move to 10.5 I will give Inkscape another try.

I don’t have an iPhone, therefore I can not try Intaglio for the iPhone, but
I guess this feature would be of interest in that case too.

I really don’t see why it would hurt to have the functionality and let the
user decide whether to use it or not.

It would not hurt. I was just teasing you on this last.

Regards
–schremme


Intaglio mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options


http://juliuspaintings.co.uk
I’m looking for comments re: http://juliuspaintings.co.uk/physics-of-thought


Intaglio mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

On Mar 20, 2010, at 10:20 PM, julius wrote:

Here’s my two pence worth if it’s worth anything.

In my view, it was worth at least three pence.

Quite a few years ago I wanted to smooth curves for pattern
recognition purposes and as Allain has pointed out the idea of what
constitutes an appropriate degree of smoothing is something that a
particular human might know but a machine not. Since what I was
engaged on was what was then thought of as “capturing human
expertiese” I looked at what might be the criteria a human used
when evaluating such a problem. One approach, indeed the approach I
gave some consideration too (and as I noted later in the literature
did others) was the idea of increasing the smoothing parameter,
e.g. the width of the convolving window in stages and noting the
parameter values at which peaks in the curve disappeared. Then idea
then would be to use this notion to do whatever.

So in the present case, should one want to smooth a given curve but
the degree of smoothing was a matter of human judgement one might,
most simply, allow the user to increase the smoothing parameter(s)
or to specify the number of peaks required in the curve. Presumably
Inkscape uses something like this.

Notice that this suggestion ignores the difficulties of defining
what constitutes a peak, e.g. in a wiggly spiral or in a wiggly
labyrinthine line, but the idea of allowing the user to vary the
smoothing parameter(s) is not technically difficult. This
suggestion also ignores that smoothing is a flattening process so
that should you for instance have drawn your peaks at particular
places and hoped they would stay put after smoothing then they will
not.

Kidding aside, I hadn’t given the stuff much thought and I found this
all quite interesting. I would just point out that peaks depend on a
notion of verticality. How about “bumps”? Which is why, in the
experiment I had suggested at the outset, I mentioned rotating the
figure.

My own view, for what it’s worth tends to side with Allain’s
pessimism/realism except in so far that let us say that Intaglio
implements this user variable smoothing parameter and people find
it useful

I must have missed something. Does Intaglio truly have a smoothing tool?

in which case there’s nothing to argue about other than the degree
of utility versus the time or cost of implementing the interface
and associated mechanism. I think bezier curves with handles and
the ability to move, add or delete the control points are pretty
good and as with most things require a degree of skill to use
effectively.

Did I say that Bezier curves etc was not good? I hope I didn’t come
across as saying so. Bezier curves are GOOD. I just meant to say that
I could not see an algorithm deciding all by itself how much to
smooth a polygonal line. After all, as you almost said, the ultimate
smoothing would be a straight line.

Automation is good when you can specify exactly what it is that you
want the machine to do. It is useless when your definition includes
human psychology which is beyond our understanding.

I wish I could have said it that succinctly.

Regards
-schremmer


Intaglio mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

On 21 Mar 2010, at 02:52, Alain Schremmer wrote:

On Mar 20, 2010, at 10:20 PM, julius wrote:

My own view, for what it’s worth tends to side with Allain’s pessimism/realism except in so far that let us say that Intaglio implements this user variable smoothing parameter and people find it useful

I must have missed something. Does Intaglio truly have a smoothing tool?

Sorry to have been unclear. This was meant to be a “let us suppose that Intaglio had acquired such a tool and etc” kind of statement.

in which case there’s nothing to argue about other than the degree of utility versus the time or cost of implementing the interface and associated mechanism. I think bezier curves with handles and the ability to move, add or delete the control points are pretty good and as with most things require a degree of skill to use effectively.

Did I say that Bezier curves etc was not good? I hope I didn’t come across as saying so. …

Again sorry. I did not mean to imply anything of the kind.
And I must remember never to start writing e-mails when just back from the pub.
Oh, and my beloved has just asked if I were once again swimming in the Saragasso sea!
I must away!!!..

All the best
Julius


http://juliuspaintings.co.uk
I’m looking for comments re: http://juliuspaintings.co.uk/physics-of-thought


Intaglio mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

On Mar 21, 2010, at 8:19 AM, julius wrote:

On 21 Mar 2010, at 02:52, Alain Schremmer wrote:

On Mar 20, 2010, at 10:20 PM, julius wrote:

My own view, for what it’s worth tends to side with Allain’s
pessimism/realism except in so far that let us say that Intaglio
implements this user variable smoothing parameter and people find
it useful

I must have missed something. Does Intaglio truly have a smoothing
tool?

Sorry to have been unclear. This was meant to be a “let us suppose
that Intaglio had acquired such a tool and etc” kind of statement.

in which case there’s nothing to argue about other than the
degree of utility versus the time or cost of implementing the
interface and associated mechanism. I think bezier curves with
handles and the ability to move, add or delete the control points
are pretty good and as with most things require a degree of skill
to use effectively.

Did I say that Bezier curves etc was not good? I hope I didn’t
come across as saying so. …

Again sorry. I did not mean to imply anything of the kind.
And I must remember never to start writing e-mails when just back
from the pub.

Well, looking back, I think I sounded a tad acrimonious so it is I
who should apologize, particularly given that I missed your “let us
say”.

Regards
–schremmer


Intaglio mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

Let us hope that Intaglio developers will let us know what they think.

Best
Daniele


Intaglio mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

On a practical note, a few years back I wrote an Applescript to do this in Intaglio. As other posters have noted, it’s not easy to come up with an algorithm to do smoothing, since it’s rather subjective. I enclose the script below. Draw a closed polygon and select it. Then run the script.

As far as I can tell now, the script works by drawing a smooth curve that, at each point of the polygon, is tangent to the line that goes through the point and makes equal angles with both the lines connected to the point. The length of the Bezier handles is adjusted according to the distance between the points.

One obvious issue is that it doesn’t correctly handle concave polygons. This should be fixable, and is the worst flaw, I think. Another is that, for a convex polygon, the smoothed curve always lies outside of the polygon, which is not always what one is looking for.

It’s actually surprising how well this somewhat crude algorithm works, though.

tell application “Intaglio”
set g to selection
set g to item 1 of g
set thePoints to every point in g

set newPoints to {}

set N to count of thePoints
repeat with i from 1 to N
	if (i = 1) then -- pa = point before the current point
		set pa to item N of thePoints
	else
		set pa to item (i - 1) of thePoints
	end if
	set p to item i of thePoints -- p = current point
	if (i = N) then
		set pb to item 1 of thePoints -- pb = point after the current point
	else
		set pb to item (i + 1) of thePoints
	end if
	
	set x to item 1 of (get value of p) -- x, y of current point
	set y to item 2 of (get value of p)
	set xa to item 1 of (get value of pa) -- x, y of point before current point
	set ya to item 2 of (get value of pa)
	set xb to item 1 of (get value of pb) -- x, y of point after current point
	set yb to item 2 of (get value of pb)
	log x
	log y
	log xa
	log ya
	log xb
	log yb
	set ax to xa - x -- These are components of vectors a, b from point p to points pa and pb.
	set ay to ya - y
	set bx to xb - x
	set byy to yb - y -- "by" is reserved. Ouch.
	
	
	set a to (ax ^ 2 + ay ^ 2) ^ (1 / 2) -- Lengths of those vectors
	set b to (bx ^ 2 + byy ^ 2) ^ (1 / 2)
	
	set cx to ax / a + bx / b -- c is the sum of the unit vectors in the a and b directions
	set cy to ay / a + byy / b
	
	set ex to -cy / ((cx ^ 2 + cy ^ 2) ^ (1 / 2)) -- e is a unit vector perpendicular to c.
	set ey to cx / ((cx ^ 2 + cy ^ 2) ^ (1 / 2))
	
	
	
	--set alpha to (b * ax + a * bx) / (b * ay + a * byy) -- ratio of the x to y component of the sum of the unit vectors in the a and b directions.
	
	--set cx to (1 / 12) * (a + b) / ((1 + alpha ^ 2) ^ (1 / 2))
	--set cy to -alpha * cx
	set alpha to 0.35
	
	set cxa to x + alpha * a * ex
	set cya to y + alpha * a * ey
	set cxb to x - alpha * b * ex
	set cyb to y - alpha * b * ey
	
	set end of newPoints to {{x, y}, {cxb, cyb}, {cxa, cya}}
	
end repeat

set N to count of thePoints
repeat with i from 1 to N
	
	set p to item i of thePoints
	set value of p to item i of newPoints
end repeat

end tell


Intaglio mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options