<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: How to calculate/get 4 points (and angle) of a rectangle by two corners in .NET Maps SDK Questions</title>
    <link>https://community.esri.com/t5/net-maps-sdk-questions/how-to-calculate-get-4-points-and-angle-of-a/m-p/1292469#M11848</link>
    <description>&lt;P&gt;Hi Johannes,&lt;/P&gt;&lt;P&gt;and thanks for the great explanation and phyton code. I'll give it a try to port it to C#.&lt;/P&gt;&lt;P&gt;About the two solutions: The two points are always lower-left, upper-right. So solution 1 is the right one for me.&lt;/P&gt;&lt;P&gt;One thing though I'm worried about:&lt;BR /&gt;This pure trigonometry solution works for sure in a "standard"&amp;nbsp;coordinate system. By "standard" I mean were X and Y distances/units are the same.&lt;/P&gt;&lt;P&gt;But longitude and latitute distances are not the same afaik. Apparently even one unit/degree is a different distance depending where you are on the globe.&lt;/P&gt;&lt;P&gt;Do you think this matters?&lt;/P&gt;&lt;P&gt;Soko&lt;/P&gt;</description>
    <pubDate>Wed, 24 May 2023 08:52:10 GMT</pubDate>
    <dc:creator>SokoFromNZ</dc:creator>
    <dc:date>2023-05-24T08:52:10Z</dc:date>
    <item>
      <title>How to calculate/get 4 points (and angle) of a rectangle by two corners</title>
      <link>https://community.esri.com/t5/net-maps-sdk-questions/how-to-calculate-get-4-points-and-angle-of-a/m-p/1292303#M11844</link>
      <description>&lt;P&gt;Hi guys,&lt;/P&gt;&lt;P&gt;I'm kinda lost with my problem after hours of reading and research so I hope you can help!&lt;/P&gt;&lt;P&gt;I have two points (red) on a map like this:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="SokoFromNZ_0-1684872707779.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/71470i208D380DEE98DF9C/image-size/medium?v=v2&amp;amp;px=400" role="button" title="SokoFromNZ_0-1684872707779.png" alt="SokoFromNZ_0-1684872707779.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;And I like to calculate the two other points and angle in degrees of the rectangle (blue arrows) for a given aspect ratio of the rectangle:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="SokoFromNZ_1-1684873356520.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/71473i1CCAB05DFDD643C7/image-size/medium?v=v2&amp;amp;px=400" role="button" title="SokoFromNZ_1-1684873356520.png" alt="SokoFromNZ_1-1684873356520.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;I do not need to draw them on a map, just calculation and just in 2D&amp;nbsp;&lt;SPAN&gt;Cartesian mathematics.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;I've looked through all the&amp;nbsp;&lt;A href="https://developers.arcgis.com/net/api-reference/api/netwin/Esri.ArcGISRuntime/Esri.ArcGISRuntime.Geometry.GeometryEngine.html" target="_self"&gt;GeometryEngine&lt;/A&gt;&amp;nbsp;methods and couldn't find anything I can do a rotation of a Polyline for example...&lt;/P&gt;&lt;P&gt;It may be possible to do it with&amp;nbsp;&lt;A href="https://developers.arcgis.com/net/api-reference/api/netwin/Esri.ArcGISRuntime/Esri.ArcGISRuntime.Geometry.GeometryEngine.Extend.html" target="_self"&gt;Extend&lt;/A&gt;&amp;nbsp;and&amp;nbsp;&lt;A href="https://developers.arcgis.com/net/api-reference/api/netwin/Esri.ArcGISRuntime/Esri.ArcGISRuntime.Geometry.GeometryEngine.Intersections.html" target="_self"&gt;Intersections&lt;/A&gt;&amp;nbsp;(also mentioned &lt;A href="https://community.esri.com/t5/net-maps-sdk-questions/using-geometryengine-intersection-computes-cannot/m-p/352134" target="_self"&gt;here&lt;/A&gt;) once I can draw the green rectangle... but its kinda complicated.&lt;/P&gt;&lt;P&gt;Anyhow: How do I get/draw the four sides of this rectangle?&lt;/P&gt;&lt;P&gt;Also&amp;nbsp;&lt;A href="https://developers.arcgis.com/net/api-reference/api/netwin/Esri.ArcGISRuntime/Esri.ArcGISRuntime.Geometry.MultipointBuilder.html" target="_self"&gt;MultipointBuilder&lt;/A&gt;&amp;nbsp;looks promising... but can it draw a rectangle?&lt;/P&gt;&lt;P&gt;Finally reading through&amp;nbsp;&lt;A href="https://developers.arcgis.com/net/spatial-and-data-analysis/geometry/" target="_self"&gt;geometry help&lt;/A&gt;&amp;nbsp;and&amp;nbsp;&lt;A href="https://developers.arcgis.com/net/spatial-and-data-analysis/make-measurements/" target="_self"&gt;make-measurements&lt;/A&gt;&amp;nbsp;didn't really help. Although it mentions&amp;nbsp;&lt;A href="https://developers.arcgis.com/net/api-reference/api/netwin/Esri.ArcGISRuntime/Esri.ArcGISRuntime.Geometry.AngularUnits.html" target="_self"&gt;AngularUnits&lt;/A&gt;&amp;nbsp;it does not say how to determine an angle of a Polyline or Segment.&lt;/P&gt;&lt;P&gt;Thanks for your help!&lt;/P&gt;&lt;P&gt;Soko&lt;/P&gt;&lt;P&gt;PS: Am I overthinking this to much in a big way? Can I do the calculations with simple trigonometry instead of GeoemtryEngine methods?&lt;/P&gt;</description>
      <pubDate>Tue, 23 May 2023 20:58:12 GMT</pubDate>
      <guid>https://community.esri.com/t5/net-maps-sdk-questions/how-to-calculate-get-4-points-and-angle-of-a/m-p/1292303#M11844</guid>
      <dc:creator>SokoFromNZ</dc:creator>
      <dc:date>2023-05-23T20:58:12Z</dc:date>
    </item>
    <item>
      <title>Re: How to calculate/get 4 points (and angle) of a rectangle by two corners</title>
      <link>https://community.esri.com/t5/net-maps-sdk-questions/how-to-calculate-get-4-points-and-angle-of-a/m-p/1292343#M11845</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;P&gt;&lt;SPAN&gt;Am I overthinking this to much in a big way? Can I do the calculations with simple trigonometry instead of GeoemtryEngine methods?&lt;/SPAN&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;Probably. I don't know anything about the .Net SDK, but here is what you could do in pure Python (without&amp;nbsp; using the arcpy geometry methods):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import math

# some basic trigonometry functions
# points as coordinate tuples
# angles in radians
def distance(p1, p2):
    return math.sqrt(math.pow(p1[0] - p2[0], 2) + math.pow(p1[1] - p2[1], 2))
def angle(p1, p2):
    return math.atan2(p2[1] - p1[1], p2[0] - p1[0])
def point_from_angle_and_distance(p, a, d):
    return (p[0] + d * math.cos(a), p[1] + d * math.sin(a))
    
    
def get_rectangle(p1, p2, aspect):
    """ Outputs the vertices of the (a) rectangle defined by the two given corner points and the aspect ratio.
    
    p1, p2: Coordinate tuples of two points in a diagonal of the rectangle
    aspect: ratio of the two sites (&amp;lt;= 1)
    """
    # get the center of the diagonal
    a_p1p2 = angle(p1, p2)
    d_p1p2 = distance(p1, p2)
    center = point_from_angle_and_distance(p1, a_p1p2, d_p1p2 / 2)
    
    # convert the aspect ratio to angle between the diagonals
    a_diag = math.pi - 2 * math.atan(aspect)
    
    # get the other two points
    p3 = point_from_angle_and_distance(center, a_p1p2 - a_diag, d_p1p2 / 2)
    p4 = point_from_angle_and_distance(center, a_p1p2 + math.pi - a_diag, d_p1p2 / 2)
    
    # reorder and return
    return [p1, p3, p2, p4]&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Now let's give that method a spin... We will read from a Multipoint layer, convert the multipoints to coordinate tuples, calculate the resulting rectangle for multiple aspect ratios, convert those rectangles into arcpy.Polygons and write them into a polygon layer.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;aspect_ratios = [0.01, 0.25, 0.5, 0.75, 1]
with arcpy.da.InsertCursor("TestPolygons", ["SHAPE@", "DoubleField1"]) as i_cursor:
    with arcpy.da.SearchCursor("TestMultipoints", ["SHAPE@"]) as s_cursor:
        for shp, in s_cursor:
            p1 = (shp.firstPoint.X, shp.firstPoint.Y)
            p2 = (shp.lastPoint.X, shp.lastPoint.Y)
            for aspect in aspect_ratios:
                rect_points = get_rectangle(p1, p2, aspect)
                vertices = [arcpy.Point(p[0], p[1]) for p in rect_points]
                poly = arcpy.Polygon(arcpy.Array(vertices), spatial_reference=arcpy.SpatialReference(25833))
                i_cursor.insertRow([poly, aspect])&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;Result:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="JohannesLindner_0-1684882175048.png" style="width: 999px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/71493i08BB0B17637FF254/image-size/large?v=v2&amp;amp;px=999" role="button" title="JohannesLindner_0-1684882175048.png" alt="JohannesLindner_0-1684882175048.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So yeah, you just need basic trigonometry for this.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 24 May 2023 07:41:26 GMT</pubDate>
      <guid>https://community.esri.com/t5/net-maps-sdk-questions/how-to-calculate-get-4-points-and-angle-of-a/m-p/1292343#M11845</guid>
      <dc:creator>JohannesLindner</dc:creator>
      <dc:date>2023-05-24T07:41:26Z</dc:date>
    </item>
    <item>
      <title>Re: How to calculate/get 4 points (and angle) of a rectangle by two corners</title>
      <link>https://community.esri.com/t5/net-maps-sdk-questions/how-to-calculate-get-4-points-and-angle-of-a/m-p/1292437#M11847</link>
      <description>&lt;P&gt;PS: This problem has two solutions, depending on which diagonal the two point describe. If you change line 26 to take the arctan of 1/aspect, you get the second solution.&lt;/P&gt;&lt;P&gt;Left: solution 1 -&amp;gt; atan(aspect), Right: solution 2 -&amp;gt; atan(1/aspect)&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="JohannesLindner_0-1684912143548.png" style="width: 999px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/71521iEC7A44E516F0BEAB/image-size/large?v=v2&amp;amp;px=999" role="button" title="JohannesLindner_0-1684912143548.png" alt="JohannesLindner_0-1684912143548.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 24 May 2023 07:43:11 GMT</pubDate>
      <guid>https://community.esri.com/t5/net-maps-sdk-questions/how-to-calculate-get-4-points-and-angle-of-a/m-p/1292437#M11847</guid>
      <dc:creator>JohannesLindner</dc:creator>
      <dc:date>2023-05-24T07:43:11Z</dc:date>
    </item>
    <item>
      <title>Re: How to calculate/get 4 points (and angle) of a rectangle by two corners</title>
      <link>https://community.esri.com/t5/net-maps-sdk-questions/how-to-calculate-get-4-points-and-angle-of-a/m-p/1292469#M11848</link>
      <description>&lt;P&gt;Hi Johannes,&lt;/P&gt;&lt;P&gt;and thanks for the great explanation and phyton code. I'll give it a try to port it to C#.&lt;/P&gt;&lt;P&gt;About the two solutions: The two points are always lower-left, upper-right. So solution 1 is the right one for me.&lt;/P&gt;&lt;P&gt;One thing though I'm worried about:&lt;BR /&gt;This pure trigonometry solution works for sure in a "standard"&amp;nbsp;coordinate system. By "standard" I mean were X and Y distances/units are the same.&lt;/P&gt;&lt;P&gt;But longitude and latitute distances are not the same afaik. Apparently even one unit/degree is a different distance depending where you are on the globe.&lt;/P&gt;&lt;P&gt;Do you think this matters?&lt;/P&gt;&lt;P&gt;Soko&lt;/P&gt;</description>
      <pubDate>Wed, 24 May 2023 08:52:10 GMT</pubDate>
      <guid>https://community.esri.com/t5/net-maps-sdk-questions/how-to-calculate-get-4-points-and-angle-of-a/m-p/1292469#M11848</guid>
      <dc:creator>SokoFromNZ</dc:creator>
      <dc:date>2023-05-24T08:52:10Z</dc:date>
    </item>
    <item>
      <title>Re: How to calculate/get 4 points (and angle) of a rectangle by two corners</title>
      <link>https://community.esri.com/t5/net-maps-sdk-questions/how-to-calculate-get-4-points-and-angle-of-a/m-p/1292526#M11850</link>
      <description>&lt;P&gt;Oh right. this calculation is for cartesian coordinate systems, as per your question.&lt;/P&gt;&lt;P&gt;I have only worked with projected coordinate systems until now, so I'm not really sure how this will play out in a geographical coordinate system. The error &lt;EM&gt;might&lt;/EM&gt; be negligible over small distances, but for greater distances, it will probably become apparent.&lt;/P&gt;&lt;P&gt;Maybe you can get away with converting the points into a locally applicable projected coordinate system, do the calculation, and then project the resulting points into the geographic system.&lt;/P&gt;</description>
      <pubDate>Wed, 24 May 2023 13:16:15 GMT</pubDate>
      <guid>https://community.esri.com/t5/net-maps-sdk-questions/how-to-calculate-get-4-points-and-angle-of-a/m-p/1292526#M11850</guid>
      <dc:creator>JohannesLindner</dc:creator>
      <dc:date>2023-05-24T13:16:15Z</dc:date>
    </item>
  </channel>
</rss>

