Home Forums Nazca _trapezoid() in nd.util

Tagged:

Viewing 4 posts - 1 through 4 (of 4 total)
• Author
Posts
• #5627
paul
Member

Hi,

I have some problem understanding the trapezoid function in nazca.util (I would like to slightly modify polyline2polygon(), that’s why I’m looking into it)

It works very well even though the docstring says that it returns the coordinates from top left to bottom left, whereas I think that this is the opposite.

Apart from that I just don’t understand the algorithm. What is the intended meaning of the dx and dy variables, and more importantly the px, py ones. I have spent some time looking into it with pen and paper but I just don’t see it!
Not hugely essential as I don’t think that it prevents me to do what I would like to, but any pointers would be appreciated.

Paul

#5629
Ronald
Keymaster

Dear Paul,

The _trapezoid draws a symmetrical trapezoid with base width w0 and top width w1, The central axis between the base and top runs between points xy0 = (x0, y0) and xy1 = (x1, y1). Note that the trapezoid can, therefore, have any orientation in the xy coordinate system. The “top-left” terminology in de docs string (version 0.5.2) is, therefore, relative and depends on the actual start xy0 and end xy1 coordinates. The ‘counter clockwise’ in the doc is also relative and it seems better to remove it. This may be a more clear doc string:

``````def _trapezoid(xy0, xy1, w0, w1):
"""Calculate the four coordinates of the trapezoid that is defined by the
line segment through two points xy0 and xy1 with widths w0 and w1.

Args:
xy0 (float, float): point (x,y), segment start
xy1 (float, float): point (x,y), segment end
w0 (float): width of line segment start
w1 (float): width of line segment end

Returns:
list of (float, float): list of 4 (float, float) point coordinates (x, y)
tracing the outline of the trapezoid.
"""``````

Ronald

#5630
Xaveer
Moderator

Dear Paul,

Also note that the leading underscore in _trapezoid() indicates that this function is for internal use, which means that it is not guaranteed to behave in the same way (or even exist) in a next version of Nazca.
The implementation of polyline2polygon() has changed significantly in version 0.5.2, where the width can vary along the curve.
To help us understand the problem, please remember next time to mention the specific Nazca version you’re referring to.

Xaveer

#5632
paul
Member

Hi Xaveer,

I’m using Nazca 0.5.1
In the end I was looking at the problem sideways, that’s what I got confused.
Just wanted to make sure that I understood the function properly before using it.

Cheers,

Paul

Viewing 4 posts - 1 through 4 (of 4 total)
• You must be logged in to reply to this topic.