Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.postscript > #3406

Re: Fierce and scary geometry algorithm for ‘ParallelPath’

Newsgroups comp.lang.postscript
Date 2019-06-22 13:33 -0700
References <e7dba0a9-68e6-4dfe-90ba-6e9b00e7d3d3@googlegroups.com> <e0f28d19-18c4-4fb5-8825-597c56373326@googlegroups.com> <ec33e951-0c51-4fdd-b62e-4a65c99a9b52@googlegroups.com> <qa5h6c$dvh$1@dont-email.me> <a837e718-be44-4ff9-bd4c-e06c86e2e80e@googlegroups.com>
Message-ID <75b8871c-908d-42db-bd69-5737a3a4c29a@googlegroups.com> (permalink)
Subject Re: Fierce and scary geometry algorithm for ‘ParallelPath’
From luser droog <luser.droog@gmail.com>

Show all headers | View raw


On Wednesday, June 19, 2019 at 5:04:13 PM UTC-5, jdaw1 wrote:
> Sorry about delay in replying — original post was from wrong gmail account, and there‘s no way to stop it being my browser’s default. Sigh. 
> 
> On Sunday, 28 April 2019 21:33:08 UTC+1, luser droog  wrote:
> > … we want something like a *morph* between
> > the inner curve and the outer curve. 
> 
> No. The outer curve is merely a version of all the curves. Wha’s wanted is derived from the inner curve only. 
> 
> On Sunday, 28 April 2019 21:33:08 UTC+1, luser droog  wrote:
> > I think I should read up on 'upath' which I think handles some of the
> > gymnastics I've been doing with paths. Writing a function to take
> > two paths can't really work with the currentpath as naively as I've
> > grown used to doing.
> 
> Please report back. 
> 

I didn't do any more after posting that, but I did actually do a little
bit with the program just before I posted that. But rereading the whole
thread, I think my code doesn't address the actual problem you were 
having. And my "algorithm" boils down to roughly the same thing you were
already doing. 'stroke' uses 'strokepath'.

I should also point out that this code is very implementation dependant
and may fail to work with any other version of ghostscript which does
'strokepath' differently or any other postscript interpreter which doesn't
produce a path that's exactly of the expected form.

The new features here over the previous code are that multiple parallel
curves can be created. Rather like the fact that the result of 'strokepath'
is not meant to be strokeable, my function 'strokeable' produced a result
which could be 'stroke'd but not 'strokeable'd again.

Another side note: you should not be afraid of 'flattenpath' mostly because
'strokepath' (and hence 'stroke') already does that. Actually computing
a real offset curve is a hard problem AIUI, but offsetting a sequence of
line-segments is really easy. So PostScript has already been taking that
shortcut this whole time.

Did you experiment at all with adjusting 'setflat' on the original? That
might influence the sharpness of the clipped edges.

Anyway, the new function 'strokes' takes two arrays for left widths and
right widths and replaces the current path with corresponding left and
right offsets.

$ cat stroke.ps
%!

/args { -1 1{-1 roll =only( )print}for } def
/dumppath {
  { 2 args (moveto) = }
  { 2 args (lineto) = }
  { 6 args (curveto) = }
  { (closepath) = }
  pathforall
} def

/script {
300 400 200 0 360 arc
dumppath/ =

flattenpath
dumppath/ =

144 setlinewidth
strokepath
dumppath/ =

1 setlinewidth
stroke
} def

/path {
  [
    { [ 3 1 roll }
    { }
    { }
    { ] } pathforall
  ]
} def

/pathdraw {
  {
    dup 0 2 getinterval aload pop  moveto
    2 1 index length 2 sub getinterval
    0 2 2 index length 2 sub { % sp i
      2 copy 2 getinterval aload pop  lineto
      pop
    } for
    pop
    closepath
  } forall
} def

/righthand {
  [
    path 
    0 2 2 index length 2 sub { % ...p i
      2 copy 2 getinterval     % ...p i p_i
      0 get 0 4 getinterval    % ...p i p_ir
      3 1 roll pop             % ... p_ir p
    } for
    pop
  ]
} def

/lefthand {
  [
    path
    0 2 2 index length 2 sub { % ...p i
      2 copy 2 getinterval     % ...p i p_i
      0 get 4 4 getinterval    % ...p i p_il
      aload pop 4 2 roll 4 array astore
      3 1 roll pop
    } for
    pop
  ]
} def

/draw {
  dup 0 get aload pop 4 2 roll moveto lineto
  1 1 index length 1 sub getinterval
  {
    aload pop 4 2 roll lineto lineto
  } forall
} def

/strokeable {
  flattenpath
  strokepath
  righthand
  lefthand
  newpath
  stack
  draw
  draw
} def

/strokeleftpath {
  flattenpath
  strokepath
  lefthand
} def

/strokerightpath {
  flattenpath
  strokepath
  righthand
} def

/strokes {
  {right left}{exch def}forall
  [
    right {
      gsave
      setlinewidth
      strokerightpath
      grestore
    } for
    left {
      gsave
      setlinewidth
      strokeleftpath
      grestore
    } for
  ]
  newpath
  { draw } forall
} def

300 400 200 0 360 arc
{ 2 10 100 }{ 2 20 100 }strokes
1 setlinewidth
stroke
showpage quit


{
300 400 200 0 360 arc
50 setlinewidth
strokeable
strokeable
1 setlinewidth
stroke
showpage
} pop


/section {
499.999 399.999 moveto
499.999 405.112 lineto
498.962 420.452 lineto
495.931 440.309 lineto
491.003 459.473 lineto
484.28 477.848 lineto
475.858 495.331 lineto
465.839 511.822 lineto
454.324 527.219 lineto
441.416 541.42 lineto
427.215 554.329 lineto
411.818 565.843 lineto
395.327 575.862 lineto
377.843 584.284 lineto
359.469 591.007 lineto
340.304 595.935 lineto
320.447 598.966 lineto
305.108 599.998 lineto
299.999 599.998 lineto
} def


quit

571.755 399.999 moveto
571.755 405.112 lineto
%427.757 405.112 lineto
%427.757 399.999 lineto
%closepath
%571.755 405.112 moveto
%571.755 405.112 lineto
%571.834 409.965 lineto
%499.999 405.112 lineto
%closepath
571.834 409.965 lineto
570.797 425.304 lineto
%427.126 415.599 lineto
%428.163 400.259 lineto
%closepath
%570.797 425.304 moveto
%570.599 428.304 lineto
%570.136 431.313 lineto
%498.962 420.452 lineto
%closepath

stroke

showpage quit

Back to comp.lang.postscript | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

Fierce and scary geometry algorithm for ‘ParallelPath’ jdawiseman.bloomberg@gmail.com - 2019-04-17 13:37 -0700
  Re: Fierce and scary geometry algorithm for ‘ParallelPath’ edspikechapman@gmail.com - 2019-04-19 08:55 -0700
    Re: Fierce and scary geometry algorithm for ‘ParallelPath’ jdawiseman.bloomberg@gmail.com - 2019-04-20 02:44 -0700
      Re: Fierce and scary geometry algorithm for ‘ParallelPath’ Carlos <carlos@cvkm.cz> - 2019-04-29 02:41 +0200
        Re: Fierce and scary geometry algorithm for ‘ParallelPath’ jdaw1 <jdawiseman@gmail.com> - 2019-06-19 15:04 -0700
          Re: Fierce and scary geometry algorithm for ‘ParallelPath’ luser droog <luser.droog@gmail.com> - 2019-06-22 13:33 -0700
            Re: Fierce and scary geometry algorithm for ‘ParallelPath’ luser droog <luser.droog@gmail.com> - 2019-06-22 14:54 -0700
              Re: Fierce and scary geometry algorithm for ‘ParallelPath’ luser droog <luser.droog@gmail.com> - 2019-06-22 15:37 -0700
                Re: Fierce and scary geometry algorithm for ‘ParallelPath’ luser droog <luser.droog@gmail.com> - 2019-06-23 15:59 -0700
                Re: Fierce and scary geometry algorithm for ‘ParallelPath’ luser droog <luser.droog@gmail.com> - 2019-06-27 06:59 -0700
                Re: Fierce and scary geometry algorithm for ‘ParallelPath’ luser droog <luser.droog@gmail.com> - 2019-06-27 07:48 -0700
                Re: Fierce and scary geometry algorithm for ‘ParallelPath’ luser droog <luser.droog@gmail.com> - 2019-06-27 08:30 -0700
                Re: Fierce and scary geometry algorithm for ‘ParallelPath’ luser droog <luser.droog@gmail.com> - 2019-06-28 12:10 -0700
                Re: Fierce and scary geometry algorithm for ‘ParallelPath’ luser droog <luser.droog@gmail.com> - 2019-07-19 14:00 -0700
                Re: Fierce and scary geometry algorithm for ‘ParallelPath’ luser droog <luser.droog@gmail.com> - 2019-07-20 09:33 -0700
                Re: Fierce and scary geometry algorithm for ‘ParallelPath’ luser droog <luser.droog@gmail.com> - 2019-07-20 13:20 -0700
                Re: Fierce and scary geometry algorithm for ‘ParallelPath’ jdaw1 <jdawiseman@gmail.com> - 2021-03-14 10:25 -0700
  Re: Fierce and scary geometry algorithm for ‘ParallelPath’ jdawiseman.bloomberg@gmail.com - 2019-04-20 06:54 -0700
    Re: Fierce and scary geometry algorithm for ‘ParallelPath’ luser droog <luser.droog@gmail.com> - 2019-04-20 10:44 -0700
      Re: Fierce and scary geometry algorithm for ‘ParallelPath’ jdawiseman.bloomberg@gmail.com - 2019-04-20 11:01 -0700
        Re: Fierce and scary geometry algorithm for ‘ParallelPath’ luser droog <luser.droog@gmail.com> - 2019-04-20 11:33 -0700
          Re: Fierce and scary geometry algorithm for ‘ParallelPath’ luser droog <luser.droog@gmail.com> - 2019-04-20 11:50 -0700
            Re: Fierce and scary geometry algorithm for ‘ParallelPath’ luser droog <luser.droog@gmail.com> - 2019-04-20 13:01 -0700
              Re: Fierce and scary geometry algorithm for ‘ParallelPath’ jdawiseman.bloomberg@gmail.com - 2019-04-21 03:29 -0700
                Re: Fierce and scary geometry algorithm for ‘ParallelPath’ luser droog <luser.droog@gmail.com> - 2019-04-28 13:33 -0700

csiph-web