Re: draw text parallel to a sloping line [message #19193] |
Sat, 04 March 2000 00:00 |
davidf
Messages: 2866 Registered: September 1996
|
Senior Member |
|
|
Vinay L. Kashyap (kashyap@head-cfa.harvard.edu) writes:
> It doesn't work because >orientation< in XYOUTS does not know
> anything about the previous PLOT and the data ranges in the
> plot. Do the following:
>
> X = 24.5259 & Y = 16789.1 & Slope = -1763.03 ; data coordinates
> dX=2.2 & plot, [X-dX,X+dX], Y+[-dX,dX]*Slope
> ;{convert slope from data to device coordinates
> DATA_XY=convert_coord(X+DX*[-1,1],Y+DX*SLOPE*[-1,1],/DATA,/T O_DEVICE)
> DATA_DY=DATA_XY(1,1)-DATA_XY(1,0) & DATA_DX=DATA_XY(0,1)-DATA_XY(0,0)
> O_angle=atan(DATA_DY,DATA_DX)*!radeg
> ;end changes}
> xyouts,X,Y,'A_String_Parallel_To_A_Line',align=0.5,orient=O_ angle
Well, the solution is correct. But I think the explanation
could use a little work. :-)
It is not that XYOUTS doesn't "know anything" about the previous
PLOT. It certainly does know, by virtue of the !X.S and !Y.S
scaling parameters that get set by the PLOT command. Rather,
it is not the angle in data coordinate space we want here. It
is the angle of the text on the display. And you are correct
that we have to make the conversion from data space to
device space in order to properly calculate that angle.
Cheers,
David
--
David Fanning, Ph.D.
Fanning Software Consulting
Phone: 970-221-0438 E-Mail: davidf@dfanning.com
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Toll-Free IDL Book Orders: 1-888-461-0155
|
|
|
Re: draw text parallel to a sloping line [message #19194 is a reply to message #19193] |
Sat, 04 March 2000 00:00  |
kashyap
Messages: 26 Registered: April 1993
|
Junior Member |
|
|
It doesn't work because >orientation< in XYOUTS does not know
anything about the previous PLOT and the data ranges in the
plot. Do the following:
X = 24.5259 & Y = 16789.1 & Slope = -1763.03 ; data coordinates
dX=2.2 & plot, [X-dX,X+dX], Y+[-dX,dX]*Slope
;{convert slope from data to device coordinates
DATA_XY=convert_coord(X+DX*[-1,1],Y+DX*SLOPE*[-1,1],/DATA,/T O_DEVICE)
DATA_DY=DATA_XY(1,1)-DATA_XY(1,0) & DATA_DX=DATA_XY(0,1)-DATA_XY(0,0)
O_angle=atan(DATA_DY,DATA_DX)*!radeg
;end changes}
xyouts,X,Y,'A_String_Parallel_To_A_Line',align=0.5,orient=O_ angle
vinay
In article <38C1644C.FB280C52@risoe.dk>,
Kristian Kjaer <kristian.kjaer@risoe.dk> wrote:
> I want to draw some text parallel to a sloping line, e.g.,
> the line through (X,Y) with a given Slope:
>
> IDL> X = 24.5259 & Y = 16789.1 & Slope = -1763.03 ; data coordinates
> IDL> dX=2.2 & plot, [X-dX,X+dX], Y+[-dX,dX]*Slope
>
> Then this doesn't give the desired result:
>
> IDL> O_angle=atan(Slope)*!radeg
> IDL> xyouts,X,Y,'A_String_Parallel_To_A_Line',$
> IDL> alignment=0.5,orientation=O_angle
>
> But then, how to do?
> Any help appreciated!
--
____________________________________________________________ __________________
kashyap@head-cfa.harvard.edu 617 495 7173 [CfA/P-146] 617 496 7173 [F]
|
|
|