Hello,
I'm new to postscript - I've been modifying a file I found here: and I'm getting some funky results. I have a parameter for number of lines on the encoder. With small values (100-200) everything looks great, but when I start to increase the line count (lines get smaller and closer together) it starts to fall apart. At one point, I created a file with 360 lines, but now that won't even work. The lines begin to get pushed together and connected in odd shapes.
If we make the assumption that my code is OK, could there be something going on with the viewer (I'm using Ghostscript but I get the same or similar glitches with ps2pdf)? Or is it more likely that there is a problem with my code? (Just in case - code is below)
Thanks for your help!
-Kerry
p.s. I was also going to post images of "good" and "bad" results, but the upload to box.net link to the side is broken.
I'm new to postscript - I've been modifying a file I found here: and I'm getting some funky results. I have a parameter for number of lines on the encoder. With small values (100-200) everything looks great, but when I start to increase the line count (lines get smaller and closer together) it starts to fall apart. At one point, I created a file with 360 lines, but now that won't even work. The lines begin to get pushed together and connected in odd shapes.
If we make the assumption that my code is OK, could there be something going on with the viewer (I'm using Ghostscript but I get the same or similar glitches with ps2pdf)? Or is it more likely that there is a problem with my code? (Just in case - code is below)
Thanks for your help!
-Kerry
Code:
%!
% File: encoder_wheel.ps
% Date: 1/28/2010
% Desc: This file generates a quadrature encoder wheel, with several configurable parameters.
/in {72 mul} def
/pi 3.1415926536 def
% Encoder parameters
/lines 360 def
/outer_diameter 4 in def
/track_height 0.1 in def
/quad_phase 90 def
/cross_length 1.0 in def
% Calculated paramters
/inner_diameter outer_diameter track_height 4 mul sub def
/delta_theta 360 lines div def
/theta_offset quad_phase 360 div delta_theta mul def
/outer_mean_radius outer_diameter 2 div track_height 2 div sub def
/inner_mean_radius outer_mean_radius track_height sub def
% Helper function for merging strings (here used for inserting numbers into strings)
/mergestr {2 copy length exch length add string dup dup 4 3 roll 4 index length exch putinterval 3 1 roll exch 0 exch putinterval} def
% Text configuration
/text ( Quadrature Encoder Wheel - ) lines 10 string cvs mergestr ( Lines, ) mergestr quad_phase 10 string cvs mergestr ( degrees between tracks - THIS SIDE UP ) mergestr def
/text_diameter inner_diameter track_height 1.9 div sub def
/font_size track_height def
/font_type (Helvetica) def
% Draws the marks indicating the center of the circle
/Center_Mark {
%Cross
-0.5 cross_length mul 0 moveto cross_length 0 rlineto 0.2 setlinewidth stroke
0 -0.5 cross_length mul moveto 0 cross_length rlineto 0.2 setlinewidth stroke
} def
% Draws the outer encoder track
/Draw_Outer_Track {
0 0 moveto
gsave
0 delta_theta 360
{
gsave
rotate
outer_mean_radius 0 rmoveto
0 0 outer_mean_radius 0 delta_theta 2 div arc
track_height setlinewidth
stroke
grestore
} for
grestore
Center_Mark
} def
% Draws the inner encoder track
/Draw_Inner_Track {
0 0 moveto
gsave
theta_offset delta_theta 360 theta_offset add
{
gsave
rotate
inner_mean_radius 0 rmoveto
0 0 inner_mean_radius 0 delta_theta 2 div arc
track_height setlinewidth
stroke
grestore
} for
grestore
} def
% Text routine borrowed from Adobe Blue Book Program 10, on page 167
/insidecircletext{
circtextdict begin
/radius exch def /centerangle exch def
/ptsize exch def /str exch def
/xradius radius ptsize 3 div sub def
gsave
centerangle str findhalfangle sub rotate
str {
/charcode exch def
( ) dup 0 charcode put insideplacechar
} forall
grestore
end
} def
/circtextdict 16 dict def
circtextdict begin
/findhalfangle {
stringwidth pop 2 div
2 xradius mul pi mul div 360 mul
} def
/insideplacechar {
/char exch def
/halfangle char findhalfangle def
gsave
halfangle rotate
radius 0 translate
90 rotate
char stringwidth pop 2 div neg 0 moveto
char show
grestore
halfangle 2 mul rotate
} def
end
font_type findfont font_size scalefont setfont
/Encoder_Text {
text 18 -90 text_diameter 2 div insidecircletext
} def
/Draw_Encoder {
Draw_Outer_Track
Draw_Inner_Track
Encoder_Text
} def
outer_diameter 2 div 0.5 in add outer_diameter 2 div 0.5 in add translate Draw_Encoder
showpage
p.s. I was also going to post images of "good" and "bad" results, but the upload to box.net link to the side is broken.