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


Groups > comp.lang.postscript > #1977 > unrolled thread

General function for regular convex polygons with arcs

Started byCecil Westerhof <Cecil@decebal.nl>
First post2014-08-17 16:17 +0200
Last post2014-08-18 23:05 -0700
Articles 6 — 3 participants

Back to article view | Back to comp.lang.postscript


Contents

  General function for regular convex polygons with arcs Cecil Westerhof <Cecil@decebal.nl> - 2014-08-17 16:17 +0200
    Re: General function for regular convex polygons with arcs jdaw1 <jdawiseman@gmail.com> - 2014-08-17 12:56 -0700
      Re: General function for regular convex polygons with arcs Cecil Westerhof <Cecil@decebal.nl> - 2014-08-18 10:52 +0200
        Re: General function for regular convex polygons with arcs jdaw1 <jdawiseman@gmail.com> - 2014-08-18 10:49 -0700
        Re: General function for regular convex polygons with arcs luser- -droog <mijoryx@yahoo.com> - 2014-08-18 22:52 -0700
    Re: General function for regular convex polygons with arcs luser- -droog <mijoryx@yahoo.com> - 2014-08-18 23:05 -0700

#1977 — General function for regular convex polygons with arcs

FromCecil Westerhof <Cecil@decebal.nl>
Date2014-08-17 16:17 +0200
SubjectGeneral function for regular convex polygons with arcs
Message-ID<87ha1b6vzm.fsf@Equus.decebal.nl>
I want to write a function to draw regular convex polygons with arcs
instead of straight lines. I made an approximation for a square with:
     20    -34.5  40   60  120  arc
    -34.5   20    40  330   30  arc
     20     74.5  40  240  300  arc
     74.5   20    40  150  210  arc
    stroke

How would I make a function that would do this for convex polygons
with sides from 3 to 12 in a correct way? (If you do a ‘4  dup  scale’
on my example you see it is not more as an approximation.)

-- 
Cecil Westerhof
Senior Software Engineer
LinkedIn: http://www.linkedin.com/in/cecilwesterhof

[toc] | [next] | [standalone]


#1979

Fromjdaw1 <jdawiseman@gmail.com>
Date2014-08-17 12:56 -0700
Message-ID<66e35f14-34ca-4bd6-88a4-dd572b1f9ccb@googlegroups.com>
In reply to#1977
Well, it depends on what you want to do. If you describe the underlying motivation, that might help force the choice of algorithm.

[toc] | [prev] | [next] | [standalone]


#1982

FromCecil Westerhof <Cecil@decebal.nl>
Date2014-08-18 10:52 +0200
Message-ID<878umm6uy3.fsf@Equus.decebal.nl>
In reply to#1979
Op Sunday 17 Aug 2014 21:56 CEST schreef jdaw1:

> Well, it depends on what you want to do. If you describe the
> underlying motivation, that might help force the choice of
> algorithm.

Well I would like to have a function (arcedConvexPolygon) that takes
(at least) number of sides and sideLength.
It draws the figure in such a way that it fits in a rectangle with
sides sideLength.
With sides 3 it draws a triangle with inside arcs instead of straight
lines.
With sides 4 it draws a square with inside arcs instead of straight
lines. (A better variant of my example.)
Etcetera.
Two interesting extensions could be: the centre point of the figure and
the rotation. Default the first line is drawn at the base, but with
rotation this could be changed.

I do not ask for a complete function: I like to write it myself. (Is a
good learning experience. In writing postscript and in writing
graphical routines.) I need just some pointers to get me on my way.

-- 
Cecil Westerhof
Senior Software Engineer
LinkedIn: http://www.linkedin.com/in/cecilwesterhof

[toc] | [prev] | [next] | [standalone]


#1983

Fromjdaw1 <jdawiseman@gmail.com>
Date2014-08-18 10:49 -0700
Message-ID<b74b4d5e-5726-4183-83e9-79681a5c8295@googlegroups.com>
In reply to#1982
Geometrical calculations in PostScript can be rather detailed, but with a good sense of achievement.

So you have a list of X coordinates, and a list of Y (or one alternating list). Let's have four relevant points with X positions Xmm, Xm, Xp, Xpp and Y positions Ymm Ym Yp Ypp (think of these as working on an edge, the m is minus, the mm is double-minus, and plus and double-plus). 

Consider the line going through point m, perpendicular to the line that bisects the angle p->m->mm. And the line though p, perpendicular to the line that bisects the angle m->p->pp. 

Put the centre of your circle at the meeting place of those two lines. 

Then every corner of the polygon will be a precise spike. 

That works if filling the polygon. But if stroking it, first use it to clip, then with double the setlinewidth, stroke. 
> clipsave clip ... 2 mul setlinewidth stroke cliprestore

[toc] | [prev] | [next] | [standalone]


#1984

Fromluser- -droog <mijoryx@yahoo.com>
Date2014-08-18 22:52 -0700
Message-ID<44b5fa42-12e5-4312-a4e2-5e80e850fd3e@googlegroups.com>
In reply to#1982
On Monday, August 18, 2014 3:52:36 AM UTC-5, Cecil Westerhof wrote:
> Op Sunday 17 Aug 2014 21:56 CEST schreef jdaw1:
> 
> 
> > Well, it depends on what you want to do. If you describe the
> > underlying motivation, that might help force the choice of
> > algorithm.
> 
> Well I would like to have a function (arcedConvexPolygon) that takes
> (at least) number of sides and sideLength.
> It draws the figure in such a way that it fits in a rectangle with
> sides sideLength.
> With sides 3 it draws a triangle with inside arcs instead of straight
> lines.
> With sides 4 it draws a square with inside arcs instead of straight
> lines. (A better variant of my example.)
> Etcetera.
> Two interesting extensions could be: the centre point of the figure and
> the rotation. Default the first line is drawn at the base, but with
> rotation this could be changed.
> 
> I do not ask for a complete function: I like to write it myself. (Is a
> good learning experience. In writing postscript and in writing
> graphical routines.) I need just some pointers to get me on my way.
> 

I'd definitely start by sketching a few on paper, to identify all the
points that are needed to determine the parameters to arc. 
And I'd probably want to make another parameter for "how curvy" the
lines should be, where 0.0 :: straight lines .. 1.0 :: half-circles.

After some thought (and without having sketched it), I expect that
determining the center-points for the circles will be the trickiest,
but (for symmetrical curves) it should lie on the line that bisects
the edge being replaced and perpendicular to it.

For programming it, the big decision seems to be: how to accept the
"polygon" parameter. Two ways (at least) are possible: an array
of [x y] pairs (and a convention for whether the starting point
is or is not repeated at the end), or taking the polygon from the
current path.

Playing with the path is more fun from the programming side (IMO), 
but using the points might be more straightforward to implement from
the sketch.

[toc] | [prev] | [next] | [standalone]


#1985

Fromluser- -droog <mijoryx@yahoo.com>
Date2014-08-18 23:05 -0700
Message-ID<1c47c3c9-e2cb-42b6-96c8-17de3562f77f@googlegroups.com>
In reply to#1977
On Sunday, August 17, 2014 9:17:49 AM UTC-5, Cecil Westerhof wrote:
> I want to write a function to draw regular convex polygons with arcs
> instead of straight lines. I made an approximation for a square with:
> 
>      20    -34.5  40   60  120  arc
>     -34.5   20    40  330   30  arc
>      20     74.5  40  240  300  arc
>      74.5   20    40  150  210  arc
>     stroke
> 
> How would I make a function that would do this for convex polygons
> with sides from 3 to 12 in a correct way? (If you do a '4  dup  scale'
> on my example you see it is not more as an approximation.)
> 

This may or may not help, but here's some code that handles
some of this kind of stuff. It does a lot of conversions 
back and forth between array-of-points and path representations
of polygons. 

http://code.google.com/p/xpost/source/browse/data/clip.ps

And, of course, Bill Casselman's opus, from which I took a
lot of code (and inspiration):
www.math.ubc.ca/~cass/graphics/manual/

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.postscript


csiph-web