🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.postscript
Article #6211

Re: Spline data points to Bezier curve

#6211
From: Doug Crabill
Date: Tue, 04 Jun 1991 16:09
124 lines
3060 bytes
In article <1991Jun3.095901.3793@desire.wright.edu> cse0080@desire.wright.edu writes:

>   Help!
>
>   I need to know how to generate spline curves in PostScript when
>   all the data I have on hand is an array of data points that lie on 
>   the curve itself.  (IE: no control points for the curveto operator)
>
>   Anyone know a good way to do this?
>
>   Thanks for your assistance.
>
>   John Hansen
>   cse0080@wsu.bitnet
>   cse0080@desire.wright.edu

I had a need for this some time ago and hacked my way to a solution.
I knew that InterViews and the idraw editor in particular somehow
performed the transformation from spline data to a form PostScript
would like.  So I hacked the idraw PostScript prolog till I had a
minimum copy of their BSpl function.  I made no attempt to optimize or
modify what they have done.  All credit goes to the authors of
InterViews for this code -- I have only cut and pasted this solution.
I've added an example of how to call BSpl at the end.

Doug Crabill
Department of Computer Science
Purdue University
dgc@cs.purdue.edu


%!
/BSpl {
0 begin
storexyn
newpath
n 1 gt {
0 0 0 0 0 0 1 1 true subspline
n 2 gt {
0 0 0 0 1 1 2 2 false subspline
1 1 n 3 sub {
/i exch def
i 1 sub dup i dup i 1 add dup i 2 add dup false subspline
} for
n 3 sub dup n 2 sub dup n 1 sub dup 2 copy false subspline
} if
n 2 sub dup n 1 sub dup 2 copy 2 copy false subspline
stroke
} if
end
} dup 0 4 dict put def

/midpoint {
0 begin
/y1 exch def
/x1 exch def
/y0 exch def
/x0 exch def
x0 x1 add 2 div
y0 y1 add 2 div
end
} dup 0 4 dict put def

/thirdpoint {
0 begin
/y1 exch def
/x1 exch def
/y0 exch def
/x0 exch def
x0 2 mul x1 add 3 div
y0 2 mul y1 add 3 div
end
} dup 0 4 dict put def

/subspline {
0 begin
/movetoNeeded exch def
y exch get /y3 exch def
x exch get /x3 exch def
y exch get /y2 exch def
x exch get /x2 exch def
y exch get /y1 exch def
x exch get /x1 exch def
y exch get /y0 exch def
x exch get /x0 exch def
x1 y1 x2 y2 thirdpoint
/p1y exch def
/p1x exch def
x2 y2 x1 y1 thirdpoint
/p2y exch def
/p2x exch def
x1 y1 x0 y0 thirdpoint
p1x p1y midpoint
/p0y exch def
/p0x exch def
x2 y2 x3 y3 thirdpoint
p2x p2y midpoint
/p3y exch def
/p3x exch def
movetoNeeded { p0x p0y moveto } if
p1x p1y p2x p2y p3x p3y curveto
end
} dup 0 17 dict put def

/storexyn {
/n exch def
/y n array def
/x n array def
n 1 sub -1 0 {
/i exch def
y i 3 2 roll put
x i 3 2 roll put
} for
} def


% Now make a spline with four data points

100 100
150 150
200 125
250 300
4 BSpl
showpage
Technical Details
Message-ID: <14921@ector.cs.purdue.edu>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!bonnie.concordia.ca!uunet!europa.asd.contel.com!gatech!purdue!dgc
References: <1991Jun3.095901.3793@desire.wright.edu>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!bonnie.concordia.ca!uunet!europa.asd.contel.com!gatech!purdue!dgc
From: dgc@cs.purdue.EDU (Doug Crabill)
Newsgroups: comp.lang.postscript
Subject: Re: Spline data points to Bezier curve
Message-ID: <14921@ector.cs.purdue.edu>
Date: 4 Jun 91 16:09:35 GMT
References: <1991Jun3.095901.3793@desire.wright.edu>
Sender: news@cs.purdue.EDU
Organization: Purdue University
Lines: 124