[GRASS-user] weird results from v.distance's to_angle

Hi,

I'm getting some weird results from G6's v.distance upload=to_angle.
before filing a bug report I thought I'd check if I'm just confused..

v.to.db seems to be lacking an "option=angle" to check against for
the v.distance output connecting line map? (I guess I could do trig on
the option=start,end coords to get that)

also, I couldn't get it to work with fields (areas) as a v.distance to=
map, only the roads (lines) map worked. ?? (otherwise output connecting
line map was just the starting point coords)

#spearfish

# make a local copy of a points map
g.copy vect=archsites,arch_pts

# add some empty attribute columns
v.db.addcol arch_pts column='distance DOUBLE, theta DOUBLE'

v.distance from=arch_pts to=roads output=arch2road_lines \
  upload=dist,to_angle column=distance,theta --o

v.db.select arch_pts column=distance,theta

d.mon x0
d.vect roads col=grey
d.vect arch2field_lines col=red width=2
d.vect arch_pts color=blue icon=basic/circle

[v.distance]
to_angle: angle between the linear feature in 'to' map and
    the positive x axis, at the location of point/centroid
    in 'from' map, counterclockwise, in radians, which is
    between -PI and PI inclusive

d.what.vect arch_pts

# cat 12: road is due south of point. theta ~= 0.03
# cat 17: road is due west of point. theta ~= pi/2 ( 1.586829)
# cat 2: road is just WNW of point. theta ~= -pi/2 (-1.646191)
# cat 14: road is NE of point. theta ~= -pi/2 (-1.635028)

(cats 23 and 19 attach to the same road terminus)
# cat 23: road is SSW of point. theta ~= pi/2 (1.647741)
# cat 19: road is SW of point. theta ~= pi/2 (1.647741)
  -- here the angle is reported identical ?!?

these angles do not match the description of theta measured CCW from the
+x axis ...?

confused,
Hamish

Hamish wrote:

I'm getting some weird results from G6's v.distance
upload=to_angle.
before filing a bug report I thought I'd check if I'm just
confused..

...

[v.distance]
to_angle: angle between the linear feature in 'to' map and
    the positive x axis, at the location of point/centroid
    in 'from' map, counterclockwise, in radians, which is
    between -PI and PI inclusive

...

these angles do not match the description of theta measured
CCW from the +x axis ...?

looking in the code, I see a different description for what 'to_angle'
is meant to do:
#define TO_ANGLE 9 /* angle of linear feature in nearest point */

which makes the results I'm getting make a lot more sense. (angle *of*
nearest road segment, not angle *to* the nearest road segment)

the angle comes from Vect_point_on_line(), which is indeed slope of the
line at that nearest point along the line:
   \param angle pointer to angle of line in that point (radians, counter
                clockwise from x axis) or NULL

so it seems the option description change in r25176 was in err.
(now fixed in all branches)

but what is described by the alternate option description is probably
quite useful to the user, and a new option added to the module to
provide for that would be nice. (there are a few other relative-to-the
'from' map options listed as TODO in the code as well)

Hamish

On 14/01/12 03:15, Hamish wrote:

Hamish wrote:

I'm getting some weird results from G6's v.distance
upload=to_angle.
before filing a bug report I thought I'd check if I'm just
confused..

...

[v.distance]
to_angle: angle between the linear feature in 'to' map and
     the positive x axis, at the location of point/centroid
     in 'from' map, counterclockwise, in radians, which is
     between -PI and PI inclusive

...

these angles do not match the description of theta measured
CCW from the +x axis ...?

looking in the code, I see a different description for what 'to_angle'
is meant to do:
#define TO_ANGLE 9 /* angle of linear feature in nearest point */

which makes the results I'm getting make a lot more sense. (angle *of*
nearest road segment, not angle *to* the nearest road segment)

the angle comes from Vect_point_on_line(), which is indeed slope of the
line at that nearest point along the line:
    \param angle pointer to angle of line in that point (radians, counter
                 clockwise from x axis) or NULL

so it seems the option description change in r25176 was in err.
(now fixed in all branches)

but what is described by the alternate option description is probably
quite useful to the user, and a new option added to the module to
provide for that would be nice. (there are a few other relative-to-the
'from' map options listed as TODO in the code as well)

I don't really see how the 'alternate description' is different from what you read in the code. It says:

"angle between the linear feature in 'to' map and
the positive x axis, at the location of point/centroid"

i.e. it is clearly described as the angle 'of' the line, at the point nearest to the point/centroid in the from map...

The parameter name might be confusion, but to_angle comes from the idea of angle of the feature in the to map, just the same as to_attr, to_x, etc.

While I'm not sure which of the to_angle descriptions I prefer (in your version it is not unambiguously clear where the angle is measured as I image that the 'to' feature is a line, not a line segment) I have to admit that I prefer the descriptions in r25176 for to_along, as it makes it clear that distance is measured from the 'start' coordinate of the linear feature (i.e. right now we know whereto it measures, but not from where).

Here would be my go for both of them:

"to_along;distance to the nearest point on 'from' feature along linear feature, measured from 'start' point of that linear feature;"
"to_angle;angle of linear feature at the point nearest to point/centroid in 'from' map, counterclockwise from positive x axis, in radians, which is between -PI and PI inclusive;"

Moritz

Moritz wrote:

While I'm not sure which of the to_angle descriptions I
prefer (in your version it is not unambiguously clear where
the angle is measured as I image that the 'to' feature is a
line, not a line segment)

However we word it, I expect adding a small graphic to the help
page is ultimately going to do the best job of explaining it.

Here would be my go for both of them:

"to_along;distance to the nearest point on 'from' feature
along linear feature, measured from 'start' point of that
linear feature;"

sounds fine. (it really is from the start node of that line not the
start of that line segment, right?) maybe add a note about
v.build.polylines to the help page?

"to_angle;angle of linear feature at the point nearest to
point/centroid in 'from' map, counterclockwise from positive
x axis, in radians, which is between -PI and PI inclusive;"

one of my goals was to have it be a brief description (goal < 60 chars!)
not a full paragraph, which is why I tried to remove as many
words as possible without letting it get too ambiguous.
so:
* "point/centroid in " isn't strictly needed
* "positive x axis" -> "+x axis"
* counterclockwise -> CCW
* "which is " -> ""
* In this context Pi is a proper name not a C macro or acronym, so
   the "I" is lowercased.

otherwise '--help' on the command line looks crappy with the line-wrap.
perhaps extending the indentation code could help that, but the art of
concise technical writing is always good to practice. :slight_smile:

the main bug was that it's not the angle of the line _to_ the nearest
point, it's the angle _of the line_ at the nearest point. as long as that's
clear+correct I'm not too worried about the exact wording of it, have fun.

cheers,
Hamish

On Mon, January 16, 2012 06:08, Hamish wrote:

Moritz wrote:

"to_along;distance to the nearest point on 'from' feature
along linear feature, measured from 'start' point of that
linear feature;"

sounds fine. (it really is from the start node of that line not the
start of that line segment, right?)

Finally found the time to check. Yes, it is from the beginning of the
line. Vect_line_distance calculates both, but v.distance uses only the
distance from the beginning of the line, not the one from the beginning of
the segment.

maybe add a note about
v.build.polylines to the help page?

Good idea.

Moritz