Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Heron’s Forumula [sic] and other issues on tri-point.php #20

Open
angrave opened this issue Oct 12, 2020 · 3 comments
Open

Heron’s Forumula [sic] and other issues on tri-point.php #20

angrave opened this issue Oct 12, 2020 · 3 comments

Comments

@angrave
Copy link

angrave commented Oct 12, 2020

On the page tri-point.php

  1. "Heron’s Forumula:"
    ^ Formula is misspelt.

  2. Also a visual check of the formula suggests this is actually the Shoelace formula not Heron's formula.

  3. Adding up the area is a clever mathematical approach but it suffers from machine arithmetic issues, especially with long skinny triangles. It would be useful to discuss this limitation and how a small delta can be used to address this limitation..

@jeffThompson
Copy link
Owner

Thanks for this!

Re shoelace vs Heron – can you point me to a reference? A lot of these examples are built on examples by other folks, so it's quite possible they had it wrong and I just copied it :)

Re long/skinny triangles – can you explain how that's the case? What do you mean by "small delta"?

@angrave
Copy link
Author

angrave commented Oct 13, 2020

https://en.wikipedia.org/wiki/Shoelace_formula
It looked to me that your area formula would expand out to this form
shoelace
(image from the above above wikipedia page)

Re. small delta: The problem is machine arithmetic. Addition and multiplication does not have infinite precision. So an exact comparison can fail. This is most likely to happen if you start with non-integers (e.g. a third and many other rational numbers cannot be represented exactly) Or the results of a multiplication exceed the precision that is being used.
Similarly adding/subtracting a very small number to a very large number can result in a loss in precision. By analogy suppose I said "take 199 away from 10000" but the human computer only worked to 3 significant figures, their final result would be close but inexact.

With a little thought you can see how the error becomes a significant fraction when you subtract the result of two multiplications.
Here's an exact calculation: 5.55 x 5.55 - 5.44 x 5.66 = 30.8025 - 30.7904 = 0.0121
Now let's run this in a machine that only represents numbers to 3 significant decimal digits
5.55 x 5.55 - 5.44 x 5.66 output: 30.8 - 30.8 = 0

In all of these kinds of problems the final "==" can fail. so rather than
x == y. it is better to see if they are approximately equal, abs(x-y) < delta
where delta is typically a small number e.g. 0.00000001
An exact analysis of an appropriate delta depends on the accuracy of the machine representation, the input range and the formulas used.

Long skinny triangles are an example where you adding tiny values to large values.

Perhaps the demos work on your web page because your x,y positions are small integers, but it wont work in the general case.

@jeffThompson
Copy link
Owner

Amazing, thank you! Let me dig into this when I have a minute and will update the tutorial

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

No branches or pull requests

2 participants