<?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 do I used the random module to create triangles? in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/how-do-i-used-the-random-module-to-create/m-p/638867#M49813</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The post has been removed Xander...the 404 message with This question was &lt;STRONG&gt;&lt;SPAN class="revision-comment"&gt;voluntarily removed by its author&lt;/SPAN&gt;.&lt;/STRONG&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 13 Aug 2015 20:01:30 GMT</pubDate>
    <dc:creator>DanPatterson_Retired</dc:creator>
    <dc:date>2015-08-13T20:01:30Z</dc:date>
    <item>
      <title>How do I used the random module to create triangles?</title>
      <link>https://community.esri.com/t5/python-questions/how-do-i-used-the-random-module-to-create/m-p/638857#M49803</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have a shapefile of the world and I am trying to create 75 random triangles over this shapefile using the random package. I'm just not sure how to do this and use a for loop to create the lat and.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 13 Aug 2015 11:11:03 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-do-i-used-the-random-module-to-create/m-p/638857#M49803</guid>
      <dc:creator>fumaniwada1</dc:creator>
      <dc:date>2015-08-13T11:11:03Z</dc:date>
    </item>
    <item>
      <title>Re: How do I used the random module to create triangles?</title>
      <link>https://community.esri.com/t5/python-questions/how-do-i-used-the-random-module-to-create/m-p/638858#M49804</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;To speed up an answer...&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;What code do you have so far?&lt;/LI&gt;&lt;LI&gt;do the triangles have to have equal area?&lt;/LI&gt;&lt;LI&gt;is the orientation to remain fixed?&lt;/LI&gt;&lt;LI&gt;and out of interest...why triangles?&lt;/LI&gt;&lt;LI&gt;which version of python (2.7, 3.4)?&lt;/LI&gt;&lt;LI&gt;for what software?&lt;/LI&gt;&lt;/UL&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 13 Aug 2015 13:26:10 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-do-i-used-the-random-module-to-create/m-p/638858#M49804</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2015-08-13T13:26:10Z</dc:date>
    </item>
    <item>
      <title>Re: How do I used the random module to create triangles?</title>
      <link>https://community.esri.com/t5/python-questions/how-do-i-used-the-random-module-to-create/m-p/638859#M49805</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;... and to add to the questions asked by &lt;A href="https://community.esri.com/migrated-users/3116"&gt;Dan Patterson&lt;/A&gt; ...&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;may the triangles overlap?&lt;/LI&gt;&lt;LI&gt;are there any additional conditions that apply to size and location (located on land size between a and b)?&lt;/LI&gt;&lt;LI&gt;and yes... please tell us why you want to do this, what is your objective?&lt;/LI&gt;&lt;/UL&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 13 Aug 2015 13:47:06 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-do-i-used-the-random-module-to-create/m-p/638859#M49805</guid>
      <dc:creator>XanderBakker</dc:creator>
      <dc:date>2015-08-13T13:47:06Z</dc:date>
    </item>
    <item>
      <title>Re: How do I used the random module to create triangles?</title>
      <link>https://community.esri.com/t5/python-questions/how-do-i-used-the-random-module-to-create/m-p/638860#M49806</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You could try something like this.&amp;nbsp; It requires you to set the output spatial reference, range of lat/long values, and the&amp;nbsp; output feature class location to what you're using.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import arcpy, random

# Create list to hold groupings of coordinates
triangleCoordList = []
# Create list to hold all polygon objects
triangleList = []
# Create spatial reference parameter
sr = arcpy.Describe("C:\Users\jmccall\Desktop\Test.gdb\TriangleSRSample").spatialReference




# Set triangle counter
countTriangles = 0


# Start loop for 75 triangles
while countTriangles &amp;lt; 75:
&amp;nbsp; ## Create 3 pairs of lat/long values
&amp;nbsp; # Set coordinate counter
&amp;nbsp; countCoords = 0
&amp;nbsp; # Create list to hold coordinates for single triangle
&amp;nbsp; coordList = []
&amp;nbsp; while countCoords &amp;lt; 3:
&amp;nbsp; latLongList = []
&amp;nbsp; # Cerate list
&amp;nbsp; # Create lat value
&amp;nbsp; lat = random.uniform(50.994219776,51.066472899)
&amp;nbsp; # Create long number
&amp;nbsp; long = random.uniform(-113.772229212,-113.865563728)
&amp;nbsp; latLongList.append(long)
&amp;nbsp; latLongList.append(lat)
&amp;nbsp; # Update lat long coordinate list
&amp;nbsp; coordList.append(latLongList)
&amp;nbsp; # Update coordinate counter
&amp;nbsp; countCoords = countCoords + 1
&amp;nbsp; # Append coordinate list to complete list of coordinates
&amp;nbsp; triangleCoordList.append(coordList)
&amp;nbsp; # Update triangle counter
&amp;nbsp; countTriangles = countTriangles + 1

## Create features
# Loop through coordinate pairs in list
for feature in triangleCoordList:
&amp;nbsp; triangleList.append(arcpy.Polygon(arcpy.Array([arcpy.Point(*coords) for coords in feature]),sr))
# Copy polygon objects to the Triangle feature class
arcpy.CopyFeatures_management(triangleList, "C:\Users\jmccall\Desktop\Test.gdb\Triangle")&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 03:09:10 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-do-i-used-the-random-module-to-create/m-p/638860#M49806</guid>
      <dc:creator>JenniferMcCall4</dc:creator>
      <dc:date>2021-12-12T03:09:10Z</dc:date>
    </item>
    <item>
      <title>Re: How do I used the random module to create triangles?</title>
      <link>https://community.esri.com/t5/python-questions/how-do-i-used-the-random-module-to-create/m-p/638861#M49807</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;... and to visualize the reason for the questions:&lt;/P&gt;&lt;P&gt;&lt;IMG class="image-1 jive-image" src="https://community.esri.com/legacyfs/online/122137_pastedImage_0.png" style="max-width: 1200px; max-height: 900px;" /&gt;&lt;/P&gt;&lt;P&gt;Personally, I don't think you are interested in something like this.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Example code:&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;def main():
&amp;nbsp;&amp;nbsp;&amp;nbsp; import random
&amp;nbsp;&amp;nbsp;&amp;nbsp; import arcpy

&amp;nbsp;&amp;nbsp;&amp;nbsp; # settings
&amp;nbsp;&amp;nbsp;&amp;nbsp; x_range = (-180.0, 180.0)
&amp;nbsp;&amp;nbsp;&amp;nbsp; y_range = (-90.0, 90.0)
&amp;nbsp;&amp;nbsp;&amp;nbsp; triangles = 75
&amp;nbsp;&amp;nbsp;&amp;nbsp; sr = arcpy.SpatialReference(4326) # GC_WGS_1984
&amp;nbsp;&amp;nbsp;&amp;nbsp; fc = r"D:\Xander\GeoNet\RandomTriangles\test01.shp"

&amp;nbsp;&amp;nbsp;&amp;nbsp; feats = []
&amp;nbsp;&amp;nbsp;&amp;nbsp; for i in range(triangles):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; feat = []
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for j in range(3):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; x = random.uniform(x_range[0], x_range[1])
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; y = random.uniform(y_range[0], y_range[1])
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; pnt = arcpy.Point(x,y)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; feat.append(pnt)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; feat.append(feat[0])
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; polygon = arcpy.Polygon(arcpy.Array(feat), sr)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; feats.append(polygon)

&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.CopyFeatures_management(feats, fc)

if __name__ == '__main__':
&amp;nbsp;&amp;nbsp;&amp;nbsp; main()&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 03:09:13 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-do-i-used-the-random-module-to-create/m-p/638861#M49807</guid>
      <dc:creator>XanderBakker</dc:creator>
      <dc:date>2021-12-12T03:09:13Z</dc:date>
    </item>
    <item>
      <title>Re: How do I used the random module to create triangles?</title>
      <link>https://community.esri.com/t5/python-questions/how-do-i-used-the-random-module-to-create/m-p/638862#M49808</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I came up with this code although it is buggy. I think that the triangles are supposed to be the same size. The triangles are just supposed to be random using the import random module I wasn't given specifics about the size. She just said she needs 75 of them. Based on the example problem I configured this code. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'm not sure how to configure the loop so I can set the points/coordinates for a triangle using an array&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;import arcpy&lt;/P&gt;&lt;P&gt;import random&lt;/P&gt;&lt;P&gt;env = the path lol &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="color: #222222; font-family: arial, sans-serif; font-size: 12.8000001907349px;"&gt;feat = 'triangles.shp'&lt;/P&gt;&lt;P style="color: #222222; font-family: arial, sans-serif; font-size: 12.8000001907349px;"&gt;polygon_list = [] &lt;/P&gt;&lt;P style="color: #222222; font-family: arial, sans-serif; font-size: 12.8000001907349px;"&gt;#I will create random triangles across the world shapefile using the random module&lt;/P&gt;&lt;P style="color: #222222; font-family: arial, sans-serif; font-size: 12.8000001907349px;"&gt;for y in range (90,0,-10):&lt;/P&gt;&lt;P style="color: #222222; font-family: arial, sans-serif; font-size: 12.8000001907349px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; for x in range(-180,180,10):&lt;/P&gt;&lt;P style="color: #222222; font-family: arial, sans-serif; font-size: 12.8000001907349px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; cornersArray = arcpy.Array()&lt;/P&gt;&lt;P style="color: #222222; font-family: arial, sans-serif; font-size: 12.8000001907349px;"&gt;p1 = arcpy.Point()&lt;/P&gt;&lt;P style="color: #222222; font-family: arial, sans-serif; font-size: 12.8000001907349px;"&gt;p1.X = x&lt;/P&gt;&lt;P style="color: #222222; font-family: arial, sans-serif; font-size: 12.8000001907349px;"&gt;p1.Y = y&lt;/P&gt;&lt;P style="color: #222222; font-family: arial, sans-serif; font-size: 12.8000001907349px;"&gt;cornersArray.add(p1)&lt;/P&gt;&lt;P style="color: #222222; font-family: arial, sans-serif; font-size: 12.8000001907349px;"&gt;p2 = arcpy.Point()&lt;/P&gt;&lt;P style="color: #222222; font-family: arial, sans-serif; font-size: 12.8000001907349px;"&gt;p2.X = x + 10&lt;/P&gt;&lt;P style="color: #222222; font-family: arial, sans-serif; font-size: 12.8000001907349px;"&gt;p2.Y = y&lt;/P&gt;&lt;P style="color: #222222; font-family: arial, sans-serif; font-size: 12.8000001907349px;"&gt;cornersArray.add(p2)&lt;/P&gt;&lt;P style="color: #222222; font-family: arial, sans-serif; font-size: 12.8000001907349px;"&gt;p3 = arcpy.Point()&lt;/P&gt;&lt;P style="color: #222222; font-family: arial, sans-serif; font-size: 12.8000001907349px;"&gt;p3.X=x+10&lt;/P&gt;&lt;P style="color: #222222; font-family: arial, sans-serif; font-size: 12.8000001907349px;"&gt;p3.Y = y-10&lt;/P&gt;&lt;P style="color: #222222; font-family: arial, sans-serif; font-size: 12.8000001907349px;"&gt;cornersArray.add(p3)&lt;/P&gt;&lt;P style="color: #222222; font-family: arial, sans-serif; font-size: 12.8000001907349px;"&gt;poly = arcpy.Polygon(cornersArray)&lt;/P&gt;&lt;P style="color: #222222; font-family: arial, sans-serif; font-size: 12.8000001907349px;"&gt;polygon_list.append(poly)&lt;/P&gt;&lt;P style="color: #222222; font-family: arial, sans-serif; font-size: 12.8000001907349px;"&gt;#I will copy the features in my list to the triangle shapefile&lt;/P&gt;&lt;P style="color: #222222; font-family: arial, sans-serif; font-size: 12.8000001907349px;"&gt;arcpy.CopyFeatures_management(polygon_list,feat)&lt;/P&gt;&lt;P style="color: #222222; font-family: arial, sans-serif; font-size: 12.8000001907349px;"&gt;#I will define the projection for the triangles shapefile&lt;/P&gt;&lt;P style="color: #222222; font-family: arial, sans-serif; font-size: 12.8000001907349px;"&gt;arcpy.DefineProjection_management(feat,arcpy.SpatialReference(4326))&lt;/P&gt;&lt;P style="color: #222222; font-family: arial, sans-serif; font-size: 12.8000001907349px;"&gt;print 'Finished created the triangles' &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 13 Aug 2015 16:12:08 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-do-i-used-the-random-module-to-create/m-p/638862#M49808</guid>
      <dc:creator>fumaniwada1</dc:creator>
      <dc:date>2015-08-13T16:12:08Z</dc:date>
    </item>
    <item>
      <title>Re: How do I used the random module to create triangles?</title>
      <link>https://community.esri.com/t5/python-questions/how-do-i-used-the-random-module-to-create/m-p/638863#M49809</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I tried this code and it ran in arcpy but in arcmap no triangles showed up I'm guessing thats because in line 48 you put arcpy.Point(*coords) which has no particular coordinate? Did you use a random set of coordinates or did the triangles show up on your map? &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 13 Aug 2015 16:54:52 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-do-i-used-the-random-module-to-create/m-p/638863#M49809</guid>
      <dc:creator>fumaniwada1</dc:creator>
      <dc:date>2015-08-13T16:54:52Z</dc:date>
    </item>
    <item>
      <title>Re: How do I used the random module to create triangles?</title>
      <link>https://community.esri.com/t5/python-questions/how-do-i-used-the-random-module-to-create/m-p/638864#M49810</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;See &lt;A href="https://docs.python.org/2/tutorial/controlflow.html#unpacking-argument-lists"&gt;here&lt;/A&gt; for help on unpacking arguments. Basically, *coords is Python shorthand for "the list held in the coords variable", which in this case is the list of coordinate pairs for each point (feature), from the variable triangleCoordList.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 13 Aug 2015 17:02:05 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-do-i-used-the-random-module-to-create/m-p/638864#M49810</guid>
      <dc:creator>DarrenWiens2</dc:creator>
      <dc:date>2015-08-13T17:02:05Z</dc:date>
    </item>
    <item>
      <title>Re: How do I used the random module to create triangles?</title>
      <link>https://community.esri.com/t5/python-questions/how-do-i-used-the-random-module-to-create/m-p/638865#M49811</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi &lt;A href="https://community.esri.com/migrated-users/157189"&gt;fumani wada&lt;/A&gt; ,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;A few pointers:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;When you post cost, please follow the instructions found here: &lt;A href="https://community.esri.com/migration-blogpost/1070"&gt;Posting Code blocks in the new GeoNet&lt;/A&gt; . This will save the indents that are required for valid code&lt;/LI&gt;&lt;LI&gt;The code you provided will create more than the 75 triangles you mentioned and at this point they are not random.&lt;/LI&gt;&lt;LI&gt;I think it is recommendable to ask for specifics, since there are many possible solutions. This way you avoid doing double work&lt;/LI&gt;&lt;LI&gt;In the sample code I posted you can see how to create a polygon (triangle) and with the spatial reference, in stead of generating the featureclass and using another tool to define the projection.&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The general format is.&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;The arcpy.Polygon() takes an array and the spatial reference as parameters&lt;/LI&gt;&lt;LI&gt;The arcpy.Array is created from a list&lt;/LI&gt;&lt;LI&gt;The list contains the points (arcpy.Point) that define the coordinates repeating the first coordinate as last coordinate.&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;It is possible to make a tool that let's you play with sizes, minimum and maximum angles of the triangle, rotation, and much more. The most important thing is to know what the person that asked for it expects...&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 13 Aug 2015 17:05:17 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-do-i-used-the-random-module-to-create/m-p/638865#M49811</guid>
      <dc:creator>XanderBakker</dc:creator>
      <dc:date>2015-08-13T17:05:17Z</dc:date>
    </item>
    <item>
      <title>Re: How do I used the random module to create triangles?</title>
      <link>https://community.esri.com/t5/python-questions/how-do-i-used-the-random-module-to-create/m-p/638866#M49812</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Cross posted here: &lt;A href="http://gis.stackexchange.com/questions/158163/how-to-use-random-module-with-arcpy-to-create-polygons-in-shapefile" title="http://gis.stackexchange.com/questions/158163/how-to-use-random-module-with-arcpy-to-create-polygons-in-shapefile"&gt;python - How to use random module with ArcPy to create polygons in shapefile? - Geographic Information Systems Stack Exc…&lt;/A&gt; &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 13 Aug 2015 17:39:41 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-do-i-used-the-random-module-to-create/m-p/638866#M49812</guid>
      <dc:creator>XanderBakker</dc:creator>
      <dc:date>2015-08-13T17:39:41Z</dc:date>
    </item>
    <item>
      <title>Re: How do I used the random module to create triangles?</title>
      <link>https://community.esri.com/t5/python-questions/how-do-i-used-the-random-module-to-create/m-p/638867#M49813</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The post has been removed Xander...the 404 message with This question was &lt;STRONG&gt;&lt;SPAN class="revision-comment"&gt;voluntarily removed by its author&lt;/SPAN&gt;.&lt;/STRONG&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 13 Aug 2015 20:01:30 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-do-i-used-the-random-module-to-create/m-p/638867#M49813</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2015-08-13T20:01:30Z</dc:date>
    </item>
    <item>
      <title>Re: How do I used the random module to create triangles?</title>
      <link>https://community.esri.com/t5/python-questions/how-do-i-used-the-random-module-to-create/m-p/638868#M49814</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I though I would do another intent by creating some equilateral triangles with a size ranging between 2.5 and 10 degrees:&lt;/P&gt;&lt;P&gt;&lt;IMG class="image-1 jive-image" src="https://community.esri.com/legacyfs/online/122741_pastedImage_0.png" style="max-width: 1200px; max-height: 900px;" /&gt;&lt;/P&gt;&lt;P&gt;This is the code used (see code below). For the visualization, I calculated the area in km² using the WGS_1984_Web_Mercator_Auxiliary_Sphere (WKID: 3857) and used that to extrude and symbolize the triangles in ArcGlobe.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import random
import arcpy
import math

def main():
&amp;nbsp;&amp;nbsp;&amp;nbsp; # settings
&amp;nbsp;&amp;nbsp;&amp;nbsp; triangles = 75
&amp;nbsp;&amp;nbsp;&amp;nbsp; x_range = (-180.0, 180.0)
&amp;nbsp;&amp;nbsp;&amp;nbsp; y_range = (-85.0, 85.0)
&amp;nbsp;&amp;nbsp;&amp;nbsp; size_range = (2.5, 10) # decimal degrees
&amp;nbsp;&amp;nbsp;&amp;nbsp; sr = arcpy.SpatialReference(4326) # GC_WGS_1984
&amp;nbsp;&amp;nbsp;&amp;nbsp; fc = r"C:\GeoNet\RandomTriangles\test02.shp"

&amp;nbsp;&amp;nbsp;&amp;nbsp; feats = []
&amp;nbsp;&amp;nbsp;&amp;nbsp; for i in range(triangles):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; feat = []
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; pnt = arcpy.Point(random.uniform(x_range[0], x_range[1]),
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; random.uniform(y_range[0], y_range[1]))
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; polygon = createTriangle(pnt, random.uniform(size_range[0], size_range[1]), sr)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; polygon = movePolygonInsideExtent(polygon, x_range, y_range)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; feats.append(polygon)
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.CopyFeatures_management(feats, fc)

def createTriangle(pnt_cc, size, sr):
&amp;nbsp;&amp;nbsp;&amp;nbsp; rotation_range = (0, 120)
&amp;nbsp;&amp;nbsp;&amp;nbsp; rotation = random.uniform(rotation_range[0], rotation_range[1])
&amp;nbsp;&amp;nbsp;&amp;nbsp; feat = []
&amp;nbsp;&amp;nbsp;&amp;nbsp; for i in range(3):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; pnt = createPointAtAngleWithBearing(pnt_cc, rotation + i*120, size)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; feat.append(pnt)
&amp;nbsp;&amp;nbsp;&amp;nbsp; feat.append(feat[0])
&amp;nbsp;&amp;nbsp;&amp;nbsp; return arcpy.Polygon(arcpy.Array(feat), sr)

def createPointAtAngleWithBearing(pnt, angle, size):
&amp;nbsp;&amp;nbsp;&amp;nbsp; radius = size / math.sqrt(3) # translate side of equilateral triangle to
&amp;nbsp;&amp;nbsp;&amp;nbsp; angle = math.radians(angle)
&amp;nbsp;&amp;nbsp;&amp;nbsp; dist_x, dist_y = (radius * math.cos(angle), radius * math.sin(angle))
&amp;nbsp;&amp;nbsp;&amp;nbsp; return arcpy.Point(pnt.X + dist_x, pnt.Y + dist_y)

def movePolygonInsideExtent(polygon, x_range, y_range):
&amp;nbsp;&amp;nbsp;&amp;nbsp; ext = polygon.extent
&amp;nbsp;&amp;nbsp;&amp;nbsp; x_move, y_move = 0, 0
&amp;nbsp;&amp;nbsp;&amp;nbsp; if ext.XMin &amp;lt; x_range[0]:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; x_move = x_range[0] - ext.XMin
&amp;nbsp;&amp;nbsp;&amp;nbsp; elif ext.XMax &amp;gt; x_range[1]:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; x_move = x_range[1] - ext.XMax
&amp;nbsp;&amp;nbsp;&amp;nbsp; if ext.YMin &amp;lt; y_range[0]:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; y_move = y_range[0] - ext.YMin
&amp;nbsp;&amp;nbsp;&amp;nbsp; elif ext.YMax &amp;gt; y_range[1]:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; y_move = y_range[1] - ext.YMax

&amp;nbsp;&amp;nbsp;&amp;nbsp; if x_move != 0 or y_move != 0:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; feat = []
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for part in polygon:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for pnt in part:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; pnt = arcpy.Point(pnt.X + x_move, pnt.Y + y_move)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; feat.append(pnt)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return arcpy.Polygon(arcpy.Array(feat), polygon.spatialReference)
&amp;nbsp;&amp;nbsp;&amp;nbsp; else:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return polygon

if __name__ == '__main__':
&amp;nbsp;&amp;nbsp;&amp;nbsp; main()&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 03:09:16 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-do-i-used-the-random-module-to-create/m-p/638868#M49814</guid>
      <dc:creator>XanderBakker</dc:creator>
      <dc:date>2021-12-12T03:09:16Z</dc:date>
    </item>
  </channel>
</rss>

