|
From: Daniel J S. <dan...@ie...> - 2004-10-27 21:31:56
|
Harald Harders wrote:
>On Wed, 27 Oct 2004, Ethan Merritt wrote:
>
>
>
>>On Wednesday 27 October 2004 01:32 pm, Harald Harders wrote:
>>
>>
>>>>Well, not exactly nonsense. For example, say I want to have my x-axis
>>>>tic titles at an angle, and I want the end of the words to line up right
>>>>below the tic marks. I think that requires vertical alignment.
>>>>
>>>>
>>>I did not mean that is was nonsense to have a vertical alignment when
>>>using rotated text. But it is surely nonsense if the text is rotated by an
>>>angle that leads to an overlap of these lines. Simply try this:
>>> set label "first line\nsecond line" at 0,0 rotated by 85
>>>Don't you agree that this behaviour is bad?
>>>
>>>
>>Not really. It just means you need more spacing between the lines.
>>OK, 85 degrees is a bit extreme. But 60 degrees works just fine:
>>
>> set label "first line\n\nsecond line" rotate by -60
>>
>>Or maybe I'll code up a user preference setting for line spacing.
>>That is, how much vertical space is implied by an embedded "\n"
>>'set line_spacing <foo>'
>> term.c (write_multiline):
>> y += user_prefs.line_spacing * t->v_char
>>where right now line_spacing is always 1.0
>>
>>
>
>I think it is also important that the user gets control if he wants
>vertical or horizontal aligmnent resp. at which angle the axis switches.
>
>
I think what I am seeing is a slightly different hybrid. When rotating
lines of text, I'm thinking you can either rotate each line
individually, or you can rotate lines of text as a "block", i.e.,
imagine putting a box around all the lines of text indicated.
The 0 degrees rotation is obvious. The 90 degree rotation looks as
though the lines are treated as a block and rotated about a "left,
center" anchor point. And then, angles in between seem to be different,
each line rotated individually about its own "left, center" anchor
point. I'd say treating the label as a block is the way to go because
each line individually can be done with separate labels.
The user specified spacing isn't a good idea. I suggest a sort of
mathematical approach. Build a "rotation matrix" for which to multiply
the anchor points of each individual line of text. That then should
place both lines exactly where you want them. (And no special case for
the 0/90/180/270 because those will come out to the identity matrix, and
such.)
In datafile.c of the latest CVS should now be a chunk of code that
builds a 2D rotation matrix given an angle, that you may be able to make
use of:
/* Construct 2D rotation matrix. */
/* R - Matrix to construct. */
/* alpha - Rotation angle. */
/* return - TRUE means a translation is required. */
TBOOLEAN
rotation_matrix_2D(double R[][2], double alpha)
{
static double I[2][2] = {{1, 0},
{0, 1}};
#define ANGLE_TOLERANCE 0.001
if (fabs(alpha) < ANGLE_TOLERANCE) {
/* Zero angle. Unity rotation. */
memcpy(R, I, sizeof(I));
return FALSE;
} else {
R[0][0] = cos(alpha);
R[0][1] = -sin(alpha);
R[1][0] = sin(alpha);
R[1][1] = cos(alpha);
return TRUE;
}
}
If it returns TRUE, that means it is actually the identity matrix in
case you want to break and not multiply.
So the idea would be to rotate the *block* of text about the anchor
point for the *block*. Let's call that C_b. Let's call the anchor
point for the individual lines C_l#, where # is the number of the line.
The formula would be:
C'_l# = R (C_l# - C_b) + C_b
where C' means the translated position of the anchor point. Then just
use those translated points in place of what is currently used.
Dan
|