[GRASS-dev] symbol rotation is go

Hi,

I have just added a new libgis function: G_rotate_around_pt() in 6.3cvs.
(make distclean, yet again)

It rotates a point around a given center coord by a given angle.

this enables a few things--

Anything that uses D_symbol() can now pass S_stroke() a rotation angle.
(and have it do something, the stub was already there)

d.graph: you can now rotate symbols. for example, a sideways mushroom-
echo -e "rotation 45\nsymbol demo/muchomurka 120 50 50 black red" | \
    d.graph

ps.map: label boxes are now padded slightly from the point coord.
  (matches what d.labels did already; rotation safe)

possibility for wind-barb or arrow symbols to be rendered at arbitrary
angles, e.g. angle taken from an attribute column, with less low-level
display lib C coding. I've been thinking about a wind-barb fn for a
while: D_barb(double velocity, double angle) [which would need low-
level display lib C, but that's ok]

possibility for d.rast.arrow code simplification.

I've had this in d.labels as a local fn for the last week or two to
help with its label rotation code.

maybe missing: any const needed in the fn prototype?? Happy to fix that,
but no idea.

It works on integer coords, as that's all I needed for the display and
ps.map coords. It would be easy enough to add a version that takes
doubles, but I had no need for that. If needed, perhaps make the int
version a wrapper around the FP version. Don't know how much of a
performance hit that would be-- d.vect for a vector map with 2 million
points can hit D_symbol() pretty hard and take a while to run already..

enjoy,
Hamish

Good news!

Now we can start making geological maps, with symbols for foliation,
bedding planes etc rotated according to the strike angle.

One less feature that Arc has an GRASS don't.

thanks!

Carlos

On 4/26/07, Hamish <hamish_nospam@yahoo.com> wrote:

Hi,

I have just added a new libgis function: G_rotate_around_pt() in 6.3cvs.
(make distclean, yet again)

It rotates a point around a given center coord by a given angle.

this enables a few things--

Anything that uses D_symbol() can now pass S_stroke() a rotation angle.
(and have it do something, the stub was already there)

d.graph: you can now rotate symbols. for example, a sideways mushroom-
echo -e "rotation 45\nsymbol demo/muchomurka 120 50 50 black red" | \
    d.graph

ps.map: label boxes are now padded slightly from the point coord.
  (matches what d.labels did already; rotation safe)

possibility for wind-barb or arrow symbols to be rendered at arbitrary
angles, e.g. angle taken from an attribute column, with less low-level
display lib C coding. I've been thinking about a wind-barb fn for a
while: D_barb(double velocity, double angle) [which would need low-
level display lib C, but that's ok]

possibility for d.rast.arrow code simplification.

I've had this in d.labels as a local fn for the last week or two to
help with its label rotation code.

maybe missing: any const needed in the fn prototype?? Happy to fix that,
but no idea.

It works on integer coords, as that's all I needed for the display and
ps.map coords. It would be easy enough to add a version that takes
doubles, but I had no need for that. If needed, perhaps make the int
version a wrapper around the FP version. Don't know how much of a
performance hit that would be-- d.vect for a vector map with 2 million
points can hit D_symbol() pretty hard and take a while to run already..

enjoy,
Hamish

_______________________________________________
grass-dev mailing list
grass-dev@grass.itc.it
http://grass.itc.it/mailman/listinfo/grass-dev

--
+-----------------------------------------------------------+
              Carlos Henrique Grohmann - Guano
  Geologist M.Sc - Doctorate Student at IGc-USP - Brazil
Linux User #89721 - carlos dot grohmann at gmail dot com
+-----------------------------------------------------------+
_________________
"Good morning, doctors. I have taken the liberty of removing Windows
95 from my hard drive."
--The winning entry in a "What were HAL's first words" contest judged
by 2001: A SPACE ODYSSEY creator Arthur C. Clarke

Hamish wrote:

I have just added a new libgis function: G_rotate_around_pt() in 6.3cvs.
(make distclean, yet again)

It rotates a point around a given center coord by a given angle.

I would suggest an alternate version:

void G_rotate_around_point(double X0, double Y0, double *X1, double *Y1, double angle)
{
  double dx = *X1 - X0;
  double dy = *X1 - X0;
  double c = cos(D2R(angle));
  double s = sin(D2R(angle));
  double dx1 = dx * c - dy * s;
  double dy1 = dx * s + dy * c;

  *X1 = X0 + dx1;
  *Y1 = Y0 + dy1;
}

Differences:

1. Uses double for coordinates instead of int.
2. Doesn't have a singularity at (X0,Y0) (atan2(0,0) may return NaN in
some implementations).
3. "void" return type; functions returning a meaningless "int" is
usually a hold-over from pre-ANSI C.

--
Glynn Clements <glynn@gclements.plus.com>

Glynn Clements wrote:

> I have just added a new libgis function: G_rotate_around_pt() in
> 6.3cvs.
> (make distclean, yet again)
>
> It rotates a point around a given center coord by a given angle.

I would suggest an alternate version:

void G_rotate_around_point(double X0, double Y0, double *X1, double *Y1, double angle) {
  double dx = *X1 - X0;
  double dy = *X1 - X0;
  double c = cos(D2R(angle));
  double s = sin(D2R(angle));
  double dx1 = dx * c - dy * s;
  double dy1 = dx * s + dy * c;

  *X1 = X0 + dx1;
  *Y1 = Y0 + dy1;
}

Hi,

committed, with a minor fix:
-double dy = *X1 - X0;
+double dy = *Y1 - Y0;

thanks,
Hamish