Giter Club home page Giter Club logo

Comments (3)

bertt avatar bertt commented on July 30, 2024

Hi, I've added a testcase for the signed area 100197f

The signed area function assumes the polygon is closed (first point is the same as last point), maybe I should add a check on that.

In your simple triangle case it results in area == -1 (when polygon closed), its negative because polygon is defined clockwise. So I think the area calculation is correct?

I'll take an extra check on the CW/CCW issue you mention later this week.

from mapbox-vector-tile-cs.

Tom-Cuthill avatar Tom-Cuthill commented on July 30, 2024

Hi. In the definition seen in the 4.3.4.4 above, it is a positive area that is clockwise, not a negative area. This is because the Y axis is inverted. Your code claims a negative area is clockwise, but it is the opposite that is true.

    public bool IsCW()
    {
        return SignedArea() < 0;
    }

Here is your calculation for the signed area:
for (var i = 0; i < points.Count-1; i++)
{
sum = sum + (points[i].X * points[i + 1].Y - (points[i].Y * points[i + 1].X));
}

It is missing out the term for point[Count-1].X. This X value has to loop back to the point[0].Y. That is why it's called the shoelace formula, the X and Y values cross over, and the last X and Y values go back to the beginning.

shoelace

Your code misses out the XnY1 and -X1Yn terms, where n is point.Count - 1. This corrects the sign of the area and also the area itself.

from mapbox-vector-tile-cs.

bertt avatar bertt commented on July 30, 2024

can you create a pr for the code changes involved?

from mapbox-vector-tile-cs.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.