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

Area of 2D triangle can be negative #121

Open
knuesel opened this issue Jan 21, 2021 · 4 comments
Open

Area of 2D triangle can be negative #121

knuesel opened this issue Jan 21, 2021 · 4 comments

Comments

@knuesel
Copy link
Contributor

knuesel commented Jan 21, 2021

For example:

julia> area(Point2f0[[0,0], [0,1], [1,1]])
-0.5f0

The relevant area method is here:

function area(contour::AbstractVector{<:AbstractPoint{N,T}}) where {N,T}

I think there are two issues with this method:

  1. It's the generic implementation for N dimensions, but it only works for N=2, as it assumes that cross exists and returns a scalar.
  2. It's missing an abs call on the result.

Regarding the first point: there's already a specific method for N=3, and we can make one for N=2. Do we need a generic method for N>3?

@SimonDanisch
Copy link
Member

Good point!

Do we need a generic method for N>3?

Probably not :D
Sounds like a good case for only specializing on 2 & 3 .

@knuesel
Copy link
Contributor Author

knuesel commented Jan 21, 2021

Looks like the negative area was intentional:

if 0 < area(contour)

Should we leave it like this (and document it)?

@SimonDanisch
Copy link
Member

Oh, good catch :D Yeah, I guess the area function is mostly used inside GeometryBasics to figure out the winding order.

@knuesel
Copy link
Contributor Author

knuesel commented Jan 22, 2021

I made the PR for the doc change, but it is a bit inconsistent to return a signed area for 2D an a positive area for 3D... Instead, we could have area return always a positive value, and a new oriented_area that returns a signed value for 2D and a vector for 3D?

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