Irregular Polygon Program

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • pbrockway2
    Recognized Expert New Member
    • Nov 2007
    • 151

    #16
    Again slow!

    But I see in your area method you have i<myPolygon.siz e()-1, so well done!

    I'll have a think about the area...

    Comment

    • pbrockway2
      Recognized Expert New Member
      • Nov 2007
      • 151

      #17
      Here's your formula:

      0.5(X0*Y1 + X1*Y2 + ... + XN-1*Y0 - Y0*X1 - Y1*X2 - ... - YN-1*X0)

      Basically you have forgotten the bits in bold which depend on applying the "multiply and subtract" business to the last vertex and the first one. Maybe you can add this on after the for loop.

      (and maybe you should do something analogous for the perimeter. come to think of it polygons are defined as being "closed up". So a polygon with n vertices does have n sides. And there will be n little triangles to consider when figuring out the area. don't worry about this last remark unless you see where the formula came from.)

      Comment

      • r035198x
        MVP
        • Sep 2006
        • 13225

        #18
        @OP Please use code tags whenever you post code like pb-rock-way-2 was doing in his posts. His code is more readable than yours. This makes it easier for people trying to help you. It's also part of the site's posting guidelines.

        Comment

        Working...