Tagged: trapezoid
- This topic has 3 replies, 3 voices, and was last updated 5 years, 8 months ago by
paul.
-
AuthorPosts
-
27 June 2019 at 17:42 #5627
paul
MemberHi,
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
27 June 2019 at 18:26 #5629Ronald
KeymasterDear 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
27 June 2019 at 22:41 #5630Xaveer
ModeratorDear 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
28 June 2019 at 10:42 #5632paul
MemberHi 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
-
AuthorPosts
- You must be logged in to reply to this topic.