Skip to content

Conversation

TiloRC
Copy link
Contributor

@TiloRC TiloRC commented Mar 22, 2023

References to other Issues or PRs

Fixes #24885

Brief description of what is fixed or changed

For some cases, Polygon.angles returned the conjugates of the interior angles (2pi - interior angle) because it could not determine the orientation of the polygon correctly. The fix checks the sum of the computed angles against (n-2)*pi, what the interior angles should sum up to. If this sums up to the wrong value, (n+2)*pi, then the conjugates of the computed angles are returned.

Other comments

Also renamed Polygon._isright method to Polygon._is_clockwise for clarity and to avoid confusion with Triangle.is_right.

Release Notes

  • geometry
    • Fixed a bug with Polygon.angles. Formerly, incorrectly gave conjugates of interior angles for edge cases.

TiloRC added 2 commits March 22, 2023 13:23
Changes address issue sympy#24885.

To find the angles of a polygon without making assumptions about it, you have
to take into account all of its vertices in some way. Consider that if you were
given a polygon with one vertex removed, it would be impossible to tell which
angles were the interior angles and which angles were the conjugates of the
interior angles.

Previously the code determined the orientation of the polygon by checking the
orientation of only one of the angles of the polygon. I believe the method used
might work if the polygon is assumed to be convex but definitely does not work
in all cases.

The new code uses the fact that the sum of the interior angles of any polygon is
always (n-2)*180. If the computed angles don’t sum up to this, the angles
function returns the conjugates of the wrong angels instead.

I also renamed _isright to _is_clockwise to avoid confusion and better reflect
what the function does.

A note on terminology: the conjugate of an angle x is 360 -x; conjugate angles
are pairs of angles that add up to 360 degrees.

Co-authored-by: smichr
@sympy-bot
Copy link

sympy-bot commented Mar 22, 2023

Hi, I am the SymPy bot. I'm here to help you write a release notes entry. Please read the guide on how to write release notes.

Your release notes are in good order.

Here is what the release notes will look like:

  • geometry
    • Fixed a bug with Polygon.angles. Formerly, incorrectly gave conjugates of interior angles for edge cases. (#24960 by @smichr and @TiloRC)

This will be added to https://github.com/sympy/sympy/wiki/Release-Notes-for-1.13.

Click here to see the pull request description that was parsed.
<!-- Your title above should be a short description of what
was changed. Do not include the issue number in the title. -->

#### References to other Issues or PRs
<!-- If this pull request fixes an issue, write "Fixes #NNNN" in that exact
format, e.g. "Fixes #1234" (see
https://tinyurl.com/auto-closing for more information). Also, please
write a comment on that issue linking back to this pull request once it is
open. -->
Fixes https://github.com/sympy/sympy/issues/24885


#### Brief description of what is fixed or changed

For some cases, Polygon.angles returned the conjugates of the interior angles (2pi - interior angle) because it could not determine the orientation of the polygon correctly. The fix checks the sum of the computed angles against (n-2)*pi, what the interior angles should sum up to. If this sums up to the wrong value, (n+2)*pi, then the conjugates of the computed angles are returned. 


#### Other comments

Also renamed Polygon._isright method to Polygon._is_clockwise for clarity and to avoid confusion with Triangle.is_right.

#### Release Notes

<!-- Write the release notes for this release below between the BEGIN and END
statements. The basic format is a bulleted list with the name of the subpackage
and the release note for this PR. For example:

* solvers
  * Added a new solver for logarithmic equations.

* functions
  * Fixed a bug with log of integers. Formerly, `log(-x)` incorrectly gave `-log(x)`.

* physics.units
  * Corrected a semantical error in the conversion between volt and statvolt which
    reported the volt as being larger than the statvolt.

or if no release note(s) should be included use:

NO ENTRY

See https://github.com/sympy/sympy/wiki/Writing-Release-Notes for more
information on how to write release notes. The bot will check your release
notes automatically to see if they are formatted correctly. -->

<!-- BEGIN RELEASE NOTES -->
* geometry
  * Fixed a bug with Polygon.angles. Formerly, incorrectly gave conjugates of interior angles for edge cases.
<!-- END RELEASE NOTES -->

Update

The release notes on the wiki have been updated.

@github-actions
Copy link

github-actions bot commented Mar 22, 2023

Benchmark results from GitHub Actions

Lower numbers are good, higher numbers are bad. A ratio less than 1
means a speed up and greater than 1 means a slowdown. Green lines
beginning with + are slowdowns (the PR is slower then master or
master is slower than the previous release). Red lines beginning
with - are speedups.

Significantly changed benchmark results (PR vs master)

Significantly changed benchmark results (master vs previous release)

       before           after         ratio
     [8bd31f66]       [7e537b0c]
     <sympy-1.12rc1^0>                 
-      83.6±0.8ms       54.2±0.2ms     0.65  integrate.TimeIntegrationRisch02.time_doit(10)
-      82.3±0.6ms       53.6±0.2ms     0.65  integrate.TimeIntegrationRisch02.time_doit_risch(10)

Full benchmark results can be found as artifacts in GitHub Actions
(click on checks at the top of the PR).

@smichr smichr enabled auto-merge March 23, 2023 16:11
@smichr
Copy link
Member

smichr commented Mar 23, 2023

Thanks. This will merge when tests finish.

@smichr smichr merged commit 5e9de1c into sympy:master Mar 23, 2023
@TiloRC TiloRC deleted the fix-angles-bug branch June 16, 2023 06:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Polygon.angles needs correction and clarification
3 participants