Announcement

Collapse
No announcement yet.

So you're think you're good at math?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • So you're think you're good at math?

    Try this problem on for size.

    It's geometry! It's fun.

    I need an algorithm to "multiply" (expand) a polygon. A 2x multiplier will actually expand the "radius" (for lack of a better word) by 2x, so the surface area will increase obviously more than 2x. That's fine.

    The polygon is defined as a set of geographical points (lat, long) overlayed on a map.

    My current thought is to calculate the centroid of the polygon (which I've already, quite awesomely, done) and then construct a right-angle triangle with the centroid, the point I want to expand, and a new imaginary point that takes the x from the centroid and the y from the point I want to expand.

    Then I could multiply the hypotenuse and leverage SOHCAHTOA and all that fun **** to derive the other x, y offset values for the new points. I did this, quite awesomely, but then I realized this wasn't working because I was using algorithms to determine the length of the triangle sides using KILOMETERS when the points are defined as COORDINATES.

    So I'm stuck at this point. I'm trying to devise a way to calculate the new point position for each point of a polygon relative to the centroid given a multiplication factor.

    I'd like to find a way to determine the lat/long of a point given the centroid, the angle in radians, and distance (in either kilometers or coordinate "units").

    The approach I'm going to take tomorrow morning is to simply determine the length in coordinate "units" of the hypotenuse, which I've already determined like so:
    Code:
    d=acos(sin(lat1)*sin(lat2)+cos(lat1)*cos(lat2)*cos(lon1-lon2))
    where lat1/lon1 and lat2/lon2 are the lat/long of the centroid and original point location, respectively.

    I'll then multiply that number by my multiplier, then use trig to solve for the new x,y (lat/lon) offsets.

    Does this make any sense to anyone?
    "The issue is there are still many people out there that use religion as a crutch for bigotry and hate. Like Ben."
    Ben Kenobi: "That means I'm doing something right. "

  • #2
    And I do realize this is 8th grade math. **** you too.
    "The issue is there are still many people out there that use religion as a crutch for bigotry and hate. Like Ben."
    Ben Kenobi: "That means I'm doing something right. "

    Comment


    • #3
      I'm having difficulty parsing your post and watching a movie at the same time, especially since I haven't used trig in forever. What I'd do is compute the centroid as you've done, then using a polar coordinate sysem just double (or whatever) the distance of each point from the centroid without changing the angle.
      <p style="font-size:1024px">HTML is disabled in signatures </p>

      Comment


      • #4
        It's quite possible my post is not parsable. I'm **** at explaining these things without drawing.
        "The issue is there are still many people out there that use religion as a crutch for bigotry and hate. Like Ben."
        Ben Kenobi: "That means I'm doing something right. "

        Comment


        • #5
          I'm the same way when it comes to describing graphs ("so this vertex points to that vertex points to another vertex and hey wake up I'm talking here!"). Anyway, I remember it being pretty easy to convert from cartesian to polar coordinates and back again, so if I were you I'd convert the polygon to polar coordinates (using the centroid as the origin), double (or whatever) the distances, and convert back to cartesian. May not be the most efficient way, but it's simple and pretty much guaranteed to be error-free.
          <p style="font-size:1024px">HTML is disabled in signatures </p>

          Comment


          • #6
            Originally posted by loinburger View Post
            I'm having difficulty parsing your post and watching a movie at the same time, especially since I haven't used trig in forever. What I'd do is compute the centroid as you've done, then using a polar coordinate sysem just double (or whatever) the distance of each point from the centroid without changing the angle.
            I think this is essentially what I want to do. Except I forgot about the existence of this so-called Polar Coordinate System.
            "The issue is there are still many people out there that use religion as a crutch for bigotry and hate. Like Ben."
            Ben Kenobi: "That means I'm doing something right. "

            Comment


            • #7
              We may revisit this problem in the future to find more efficient ways to do it.

              I'm doing this in real-time, in Javascript, on up to 2000 points at a time.

              I'm going to try this PCS whizz-bangness tomorrow and see if it becomes my *****.
              "The issue is there are still many people out there that use religion as a crutch for bigotry and hate. Like Ben."
              Ben Kenobi: "That means I'm doing something right. "

              Comment


              • #8
                Do you want to expand by all three directions?

                Asher, what Polars do for you is rather than getting into a messy coordinate as cartesians, they let you find a number that you are very interested in, the 'radii' of the object from the com.

                Instead of XYZ, you have inside, outside and edge.

                Do you want it for n-sided polygons, or do have restricted cases?

                Edit, this is probably what you want Asher. They've got the functions here.

                Last edited by Ben Kenobi; November 25, 2009, 21:35.
                Scouse Git (2) La Fayette Adam Smith Solomwi and Loinburger will not be forgotten.
                "Remember the night we broke the windows in this old house? This is what I wished for..."
                2015 APOLYTON FANTASY FOOTBALL CHAMPION!

                Comment


                • #9
                  All 3 directions?

                  What the flying **** are you on.
                  "The issue is there are still many people out there that use religion as a crutch for bigotry and hate. Like Ben."
                  Ben Kenobi: "That means I'm doing something right. "

                  Comment


                  • #10
                    For the record, a polygon only has two dimensions it can move or be expanded in.

                    A polyhedron has three.
                    "The issue is there are still many people out there that use religion as a crutch for bigotry and hate. Like Ben."
                    Ben Kenobi: "That means I'm doing something right. "

                    Comment


                    • #11
                      To clarify, the nontriviality is that you need to scale the polygon but keep it embedded in the surface of a sphere, right?

                      Comment


                      • #12
                        Originally posted by Kuciwalker View Post
                        To clarify, the nontriviality is that you need to scale the polygon but keep it embedded in the surface of a sphere, right?
                        Correct.

                        And the polygons will be large enough that we cannot just pretend that the world is flat.
                        "The issue is there are still many people out there that use religion as a crutch for bigotry and hate. Like Ben."
                        Ben Kenobi: "That means I'm doing something right. "

                        Comment


                        • #13
                          You only need 2-d rather than 3 d? That makes it quite a bit easier.
                          Scouse Git (2) La Fayette Adam Smith Solomwi and Loinburger will not be forgotten.
                          "Remember the night we broke the windows in this old house? This is what I wished for..."
                          2015 APOLYTON FANTASY FOOTBALL CHAMPION!

                          Comment


                          • #14
                            Maps tend to be 2D.

                            I also specified that the points are defined only by lat & long, so it really should have been all kinds of obvious I'm talking about 2D here.
                            "The issue is there are still many people out there that use religion as a crutch for bigotry and hate. Like Ben."
                            Ben Kenobi: "That means I'm doing something right. "

                            Comment


                            • #15
                              You could say thank you.

                              Check the link. They should have what you need. Searching for n-polygon functions polar coordinates should get you what you need.
                              Scouse Git (2) La Fayette Adam Smith Solomwi and Loinburger will not be forgotten.
                              "Remember the night we broke the windows in this old house? This is what I wished for..."
                              2015 APOLYTON FANTASY FOOTBALL CHAMPION!

                              Comment

                              Working...
                              X