Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.postscript > #2773
| Newsgroups | comp.lang.postscript |
|---|---|
| From | Peter Billam <peter@www.pjb.com.au> |
| Subject | Re: a smooth curve through given points ? |
| References | <slrnnqr130.4f6.peter@box8.pjb.com.au> <3243f726-6885-4ae2-aac9-f8834261dc73@googlegroups.com> <slrnnqtqv6.48s.peter@box8.pjb.com.au> |
| Message-ID | <slrnnr250f.1ol.peter@box8.pjb.com.au> (permalink) |
| Date | 2016-08-15 01:00 +0000 |
| Organization | Unlimited download news at news.astraweb.com |
On 2016-08-13, Peter Billam <peter@www.pjb.com.au> wrote:
> OK, I'll give it a go (don't hold your breaths, though). I'm not
> really motivated by plotting smooth graphs, but by drawing curves
> for arty stuff, like http://www.pjb.com.au/art/posters/index.html
> It should also make it easy to copy a smooth curve from a .jpg or
> .png, because you just note the pixel-positions at a few places
> along the curve and let the algorithm do the rest. If it's not
> right yet, you insert an extra pixel-position into your list...
I have a prototype: it can either be called by
[x1 y1 x2 y2 ... xN yN] points2curve stroke
in which case is makes up its own starting and ending angles,
or by
[x1 y1 ... xN yN] initialangle finalangle points2curve stroke
if you need to fix the launch- and landing- angles, which you do
eg: for drawing smooth closed curves that join up smoothly.
The plan is to roll it into
http://www.pjb.com.au/comp/line_drawing.html
which needs a bit of revision anyway...
/xmax currentpagedevice (PageSize) get 0 get def
/ymax currentpagedevice (PageSize) get 1 get def
/points2curve { % [x1 y1 ... xN yN] initial_angle final_angle points2curve
% http://stackoverflow.com/questions/7715788/find-bezier-control-points-for-curve-passing-through-n-points
% http://www.math.ucla.edu/~baker/149.1.02w/handouts/dd_splines.pdf
% https://corner.squareup.com/2012/07/smoother-signatures.html
25 dict begin
/a_top exch def
a_top type (arraytype) eq { /points a_top def
} { /final_angle a_top def /initial_angle exch def /points exch def
} ifelse
/p_0_x points 0 get def
/p_0_y points 1 get def
p_0_x p_0_y moveto
/initial_angle where { pop /subangle_m1 initial_angle def } if
/p_im1_x p_0_x def /p_im1_y p_0_y def
2 2 points length 4 sub { /i exch def
points i get /p_i_x exch def
points i 1 add get /p_i_y exch def
points i 2 add get /p_ip1_x exch def
points i 3 add get /p_ip1_y exch def
/angle_before p_i_y p_im1_y sub p_i_x p_im1_x sub atan def
/angle_after p_ip1_y p_i_y sub p_ip1_x p_i_x sub atan def
angle_before 180 gt { /angle_before angle_before 360 sub def } if
angle_after 180 gt { /angle_after angle_after 360 sub def } if
/angle_tangent angle_before angle_after add .5 mul def
/dist_before
p_i_y p_im1_y sub dup mul p_i_x p_im1_x sub dup mul add sqrt def
/dist_after
p_i_y p_ip1_y sub dup mul p_i_x p_ip1_x sub dup mul add sqrt def
/subangle_m1 where { pop } { /subangle_m1 angle_before def } ifelse
p_im1_x subangle_m1 cos dist_before mul 0.40 mul add
p_im1_y subangle_m1 sin dist_before mul 0.40 mul add
p_i_x angle_tangent cos dist_before mul 0.40 mul sub
p_i_y angle_tangent sin dist_before mul 0.40 mul sub
p_i_x p_i_y curveto
/p_im1_x p_i_x def /p_im1_y p_i_y def
/subangle_m1 angle_tangent def
} for
/final_angle where { pop } { /final_angle subangle_m1 def } ifelse
p_i_x subangle_m1 cos dist_before mul 0.40 mul add
p_i_y subangle_m1 sin dist_before mul 0.40 mul add
p_ip1_x final_angle cos dist_before mul 0.40 mul sub
p_ip1_y final_angle sin dist_before mul 0.40 mul sub
p_ip1_x p_ip1_y curveto % last point
end
} def
xmax .002 mul setlinewidth
[ 220 50 100 100 100 200 200 250 300 210 320 100 220 50 ] 170 170
points2curve stroke
[ 400 50 380 100 430 200 360 300 450 400 380 500 410 600 400 700 ] 120 90
points2curve stroke
showpage
Regards, Peter
--
Peter Billam www.pjb.com.au www.pjb.com.au/comp/contact.html
Back to comp.lang.postscript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
a smooth curve through given points ? Peter Billam <peter@www.pjb.com.au> - 2016-08-12 08:10 +0000
Re: a smooth curve through given points ? Lawrence D’Oliveiro <lawrencedo99@gmail.com> - 2016-08-12 01:12 -0700
Re: a smooth curve through given points ? tlvp <mPiOsUcB.EtLlLvEp@att.net> - 2016-08-12 21:59 -0400
Re: a smooth curve through given points ? tlvp <mPiOsUcB.EtLlLvEp@att.net> - 2016-08-13 22:42 -0400
Re: a smooth curve through given points ? luser droog <luser.droog@gmail.com> - 2016-08-12 21:49 -0700
Re: a smooth curve through given points ? Lawrence D’Oliveiro <lawrencedo99@gmail.com> - 2016-08-12 21:59 -0700
Re: a smooth curve through given points ? luser droog <luser.droog@gmail.com> - 2016-08-12 22:21 -0700
Re: a smooth curve through given points ? luser droog <luser.droog@gmail.com> - 2016-08-18 15:01 -0700
Re: a smooth curve through given points ? luser droog <luser.droog@gmail.com> - 2016-08-19 13:10 -0700
Re: a smooth curve through given points ? luser droog <luser.droog@gmail.com> - 2016-08-19 13:13 -0700
Re: a smooth curve through given points ? luser droog <luser.droog@gmail.com> - 2016-08-12 22:00 -0700
Re: a smooth curve through given points ? Peter Billam <peter@www.pjb.com.au> - 2016-08-13 09:44 +0000
Re: a smooth curve through given points ? Peter Billam <peter@www.pjb.com.au> - 2016-08-15 01:00 +0000
Re: a smooth curve through given points ? John Forkosh <forkosh@panix.com> - 2016-08-15 03:08 +0000
Re: a smooth curve through given points ? Peter Billam <peter@www.pjb.com.au> - 2016-08-15 09:36 +0000
Re: a smooth curve through given points ? JohnF <john@please.see.sig.for.email.com> - 2016-08-16 01:28 +0000
Re: a smooth curve through given points ? Peter Billam <peter@www.pjb.com.au> - 2016-08-16 23:32 +0000
Re: a smooth curve through given points ? tlvp <mPiOsUcB.EtLlLvEp@att.net> - 2016-08-17 01:07 -0400
Re: a smooth curve through given points ? JohnF <john@please.see.sig.for.email.com> - 2016-08-14 06:17 +0000
Re: a smooth curve through given points ? jdaw1 <jdawiseman@gmail.com> - 2016-08-16 03:14 -0700
Re: a smooth curve through given points ? Alan <alan.isaac@gmail.com> - 2016-08-18 14:42 -0700
Re: a smooth curve through given points ? luser droog <luser.droog@gmail.com> - 2016-08-18 15:19 -0700
Re: a smooth curve through given points ? Alan <alan.isaac@gmail.com> - 2016-08-18 18:52 -0700
Re: a smooth curve through given points ? luser droog <luser.droog@gmail.com> - 2016-08-18 21:47 -0700
Re: a smooth curve through given points ? Alan <alan.isaac@gmail.com> - 2016-08-19 06:01 -0700
Re: a smooth curve through given points ? luser droog <luser.droog@gmail.com> - 2016-08-19 14:06 -0700
Re: a smooth curve through given points ? luser droog <luser.droog@gmail.com> - 2016-11-03 22:03 -0700
Re: a smooth curve through given points ? JohnF <john@please.see.sig.for.email.com> - 2016-11-05 05:19 +0000
Re: a smooth curve through given points ? don lancaster <don@tinaja.com> - 2016-11-05 10:12 -0700
csiph-web