Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Weird glitches with high-detail ps file

Status
Not open for further replies.

LouxK

Programmer
Feb 1, 2010
3
0
0
US
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

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.
 
There's a fault with the code not the previewer. It appears that the angles have to work out to be more than one degree and of course there are 360 degrees in a circle, hence your max value is 359 lines.
 
I don't think this is it - since my original post I discovered that I can display any number of lines in ghostscript (postscript can do floating point numbers, right? Is there some reason why the angles would have to be greater than 1 degree?). I can even do 2500 lines, and when I zoom in I can see all of the lines crystal clear. The problems really only start when I run ps2pdf. This is where the lines get screwy - and sometimes it happens with as few as 300 lines, too. If I run the same conversion several times I can get different results.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top