Skip to main content
Added language tag
Source Link
Hornbydd
  • 44.6k
  • 5
  • 42
  • 84
import numpy as np
import scipy, random

def RotateExtend(j):
    iDmax = random.randint(10, 90)  
    dMax = dAlong[iDmax]            # max deviation location (dMax)
    iLmax = random.randint(0, 30)   
    lMax = dAlong[iLmax]            # max deviation itself
    leftA = -lMax/dMax/dMax         # parabola coef left from dMax
    rightA = -lMax/(lenV-dMax)**2   # parabola coef right from dMax
##  length of perpendicular    
    sLength =np.array([lMax+(x-dMax)**2*[leftA,rightA][x>=dMax] for x in dAlong])
    i = j%2                         # left or right side of straight line
##  perpendicular end points
    sX = -dY*sLength/lenV
    sY = dX*sLength/lenV
    if i: sX+=DF_X;sY+=DF_Y
    else: sX = DF_X-sX;sY = DF_Y - sY
    points = arcpy.Array([arcpy.Point(x,y) for x,y in zip(sX,sY)])
    pLine = arcpy.Polyline(points)
    return pLine

infc = "two_points"
array = arcpy.da.FeatureClassToNumPyArray(infc, ["SHAPE@X","SHAPE@Y"])
XS,XE = array["SHAPE@X"]; dX = XE-XS
YS,YE = array["SHAPE@Y"]; dY = YE-YS
DF_X = np.linspace(XS,XE,100)
DF_Y = np.linspace(YS,YE,100)
dAlong = np.array([x[0] for x in scipy.spatial.distance.cdist(zip(DF_X,DF_Y),[[XS,YS]])])
lenV = dAlong[-1]
lines = map(RotateExtend,range(10))
outfc = arcpy.GetParameterAsText(0)
arcpy.management.CopyFeatures(lines,outfc)
import numpy as np
import scipy, random

def RotateExtend(j):
    iDmax = random.randint(10, 90)  
    dMax = dAlong[iDmax]            # max deviation location (dMax)
    iLmax = random.randint(0, 30)   
    lMax = dAlong[iLmax]            # max deviation itself
    leftA = -lMax/dMax/dMax         # parabola coef left from dMax
    rightA = -lMax/(lenV-dMax)**2   # parabola coef right from dMax
##  length of perpendicular    
    sLength =np.array([lMax+(x-dMax)**2*[leftA,rightA][x>=dMax] for x in dAlong])
    i = j%2                         # left or right side of straight line
##  perpendicular end points
    sX = -dY*sLength/lenV
    sY = dX*sLength/lenV
    if i: sX+=DF_X;sY+=DF_Y
    else: sX = DF_X-sX;sY = DF_Y - sY
    points = arcpy.Array([arcpy.Point(x,y) for x,y in zip(sX,sY)])
    pLine = arcpy.Polyline(points)
    return pLine

infc = "two_points"
array = arcpy.da.FeatureClassToNumPyArray(infc, ["SHAPE@X","SHAPE@Y"])
XS,XE = array["SHAPE@X"]; dX = XE-XS
YS,YE = array["SHAPE@Y"]; dY = YE-YS
DF_X = np.linspace(XS,XE,100)
DF_Y = np.linspace(YS,YE,100)
dAlong = np.array([x[0] for x in scipy.spatial.distance.cdist(zip(DF_X,DF_Y),[[XS,YS]])])
lenV = dAlong[-1]
lines = map(RotateExtend,range(10))
outfc = arcpy.GetParameterAsText(0)
arcpy.management.CopyFeatures(lines,outfc)

lines = map(RotateExtend,range(10))

lines = map(RotateExtend,range(**10**))
import numpy as np
import scipy, random

def RotateExtend(j):
    iDmax = random.randint(10, 90)  
    dMax = dAlong[iDmax]            # max deviation location (dMax)
    iLmax = random.randint(0, 30)   
    lMax = dAlong[iLmax]            # max deviation itself
    leftA = -lMax/dMax/dMax         # parabola coef left from dMax
    rightA = -lMax/(lenV-dMax)**2   # parabola coef right from dMax
##  length of perpendicular    
    sLength =np.array([lMax+(x-dMax)**2*[leftA,rightA][x>=dMax] for x in dAlong])
    i = j%2                         # left or right side of straight line
##  perpendicular end points
    sX = -dY*sLength/lenV
    sY = dX*sLength/lenV
    if i: sX+=DF_X;sY+=DF_Y
    else: sX = DF_X-sX;sY = DF_Y - sY
    points = arcpy.Array([arcpy.Point(x,y) for x,y in zip(sX,sY)])
    pLine = arcpy.Polyline(points)
    return pLine

infc = "two_points"
array = arcpy.da.FeatureClassToNumPyArray(infc, ["SHAPE@X","SHAPE@Y"])
XS,XE = array["SHAPE@X"]; dX = XE-XS
YS,YE = array["SHAPE@Y"]; dY = YE-YS
DF_X = np.linspace(XS,XE,100)
DF_Y = np.linspace(YS,YE,100)
dAlong = np.array([x[0] for x in scipy.spatial.distance.cdist(zip(DF_X,DF_Y),[[XS,YS]])])
lenV = dAlong[-1]
lines = map(RotateExtend,range(10))
outfc = arcpy.GetParameterAsText(0)
arcpy.management.CopyFeatures(lines,outfc)

lines = map(RotateExtend,range(10))

import numpy as np
import scipy, random

def RotateExtend(j):
    iDmax = random.randint(10, 90)  
    dMax = dAlong[iDmax]            # max deviation location (dMax)
    iLmax = random.randint(0, 30)   
    lMax = dAlong[iLmax]            # max deviation itself
    leftA = -lMax/dMax/dMax         # parabola coef left from dMax
    rightA = -lMax/(lenV-dMax)**2   # parabola coef right from dMax
##  length of perpendicular    
    sLength =np.array([lMax+(x-dMax)**2*[leftA,rightA][x>=dMax] for x in dAlong])
    i = j%2                         # left or right side of straight line
##  perpendicular end points
    sX = -dY*sLength/lenV
    sY = dX*sLength/lenV
    if i: sX+=DF_X;sY+=DF_Y
    else: sX = DF_X-sX;sY = DF_Y - sY
    points = arcpy.Array([arcpy.Point(x,y) for x,y in zip(sX,sY)])
    pLine = arcpy.Polyline(points)
    return pLine

infc = "two_points"
array = arcpy.da.FeatureClassToNumPyArray(infc, ["SHAPE@X","SHAPE@Y"])
XS,XE = array["SHAPE@X"]; dX = XE-XS
YS,YE = array["SHAPE@Y"]; dY = YE-YS
DF_X = np.linspace(XS,XE,100)
DF_Y = np.linspace(YS,YE,100)
dAlong = np.array([x[0] for x in scipy.spatial.distance.cdist(zip(DF_X,DF_Y),[[XS,YS]])])
lenV = dAlong[-1]
lines = map(RotateExtend,range(10))
outfc = arcpy.GetParameterAsText(0)
arcpy.management.CopyFeatures(lines,outfc)
lines = map(RotateExtend,range(**10**))
deleted 91 characters in body
Source Link
FelixIP
  • 23.3k
  • 3
  • 31
  • 62

This is nice geometry exercise and requires coding. To create a family of curves we can compute deviation from straight line using 2 randomly selected parameters; use parabola for smooth transition; draw variable length perpendiculars to actual line and connect their end points:

enter image description here

Note that if we pick dMax at mid point of the line (25 in this case), we'll get symmetric 'wings'.

Output for 10 lines might look like this:

enter image description here

import numpy as np
import pandas as pd
import scipy
import, random

def RotateExtend(j):
    iDmax = random.randint(10, 90)  
    dMax = DF.DISTANCE.at[iDmax]dAlong[iDmax]            # max deviation location (dMax)
    iLmax = random.randint(0, 30)   
    lMax = DF.DISTANCE.at[iLmax]dAlong[iLmax]            # max deviation itself
    leftA = -lMax/dMax/dMax         # parabola coef left from dMax
    rightA = -lMax/(lenV-dMax)**2   # parabola coef right from dMax
##  length of perpendicular    
    aList=[lMax+sLength =np.array([lMax+(x-dMax)**2*[leftA,rightA][x>=dMax] for x in DF.DISTANCE]
    DF["sLength"] = aListdAlong])
    i = j%2                         # left or right side of straight line
##  perpendicular end points
    sX = -dY*DF.sLengthdY*sLength/lenV
    sY = dX*DF.sLengthdX*sLength/lenV
    if i: sX+=DF.X;sY+=DF.YsX+=DF_X;sY+=DF_Y
    else: sX = DF.XDF_X-sX;sY = DF.YDF_Y - sY
    points = arcpy.Array([arcpy.Point(x,y) for x,y in zip(sX,sY)])
    pLine = arcpy.Polyline(points)
    return pLine

infc = "two_points"
array = arcpy.da.FeatureClassToNumPyArray(infc, ["SHAPE@X","SHAPE@Y"])
XS,XE = array["SHAPE@X"]; dX = XE-XS
YS,YE = array["SHAPE@Y"]; dY = YE-YS
DF = pd.DataFrame()
DF["X"]DF_X = np.linspace(XS,XE,100)
DF["Y"]DF_Y = np.linspace(YS,YE,100)
DF["DISTANCE"]dAlong = np.array([x[0] for x in scipy.spatial.distance.cdist(zip(DF.XDF_X,DF.YDF_Y),[[XS,YS]])])
lenV = DF.DISTANCE.max()dAlong[-1]
lines = map(RotateExtend,range(10))
outfc = arcpy.GetParameterAsText(0)
arcpy.management.CopyFeatures(lines,outfc)

If you need more than 10 polylines change this line of code accordingly:

lines = map(RotateExtend,range(10))

This is nice geometry exercise and requires coding. To create a family of curves we can compute deviation from straight line using 2 randomly selected parameters; use parabola for smooth transition; draw variable length perpendiculars to actual line and connect their end points:

enter image description here

Note that if we pick dMax at mid point of the line (25 in this case), we'll get symmetric 'wings'.

Output for 10 lines might look like this:

enter image description here

import numpy as np
import pandas as pd
import scipy
import random

def RotateExtend(j):
    iDmax = random.randint(10, 90)  
    dMax = DF.DISTANCE.at[iDmax]    # max deviation location (dMax)
    iLmax = random.randint(0, 30)   
    lMax = DF.DISTANCE.at[iLmax]    # max deviation itself
    leftA = -lMax/dMax/dMax         # parabola coef left from dMax
    rightA = -lMax/(lenV-dMax)**2   # parabola coef right from dMax
##  length of perpendicular    
    aList=[lMax+(x-dMax)**2*[leftA,rightA][x>=dMax] for x in DF.DISTANCE]
    DF["sLength"] = aList
    i = j%2                         # left or right side of straight line
##  perpendicular end points
    sX = -dY*DF.sLength/lenV
    sY = dX*DF.sLength/lenV
    if i: sX+=DF.X;sY+=DF.Y
    else: sX = DF.X-sX;sY = DF.Y - sY
    points = arcpy.Array([arcpy.Point(x,y) for x,y in zip(sX,sY)])
    pLine = arcpy.Polyline(points)
    return pLine

infc = "two_points"
array = arcpy.da.FeatureClassToNumPyArray(infc, ["SHAPE@X","SHAPE@Y"])
XS,XE = array["SHAPE@X"]; dX = XE-XS
YS,YE = array["SHAPE@Y"]; dY = YE-YS
DF = pd.DataFrame()
DF["X"] = np.linspace(XS,XE,100)
DF["Y"] = np.linspace(YS,YE,100)
DF["DISTANCE"] = scipy.spatial.distance.cdist(zip(DF.X,DF.Y),[[XS,YS]])
lenV = DF.DISTANCE.max()
lines = map(RotateExtend,range(10))
outfc = arcpy.GetParameterAsText(0)
arcpy.management.CopyFeatures(lines,outfc)

If you need more than 10 polylines change this line of code accordingly:

lines = map(RotateExtend,range(10))

This is nice geometry exercise and requires coding. To create a family of curves we can compute deviation from straight line using 2 randomly selected parameters; use parabola for smooth transition; draw variable length perpendiculars to actual line and connect their end points:

enter image description here

Note that if we pick dMax at mid point of the line (25 in this case), we'll get symmetric 'wings'.

Output for 10 lines might look like this:

enter image description here

import numpy as np
import scipy, random

def RotateExtend(j):
    iDmax = random.randint(10, 90)  
    dMax = dAlong[iDmax]            # max deviation location (dMax)
    iLmax = random.randint(0, 30)   
    lMax = dAlong[iLmax]            # max deviation itself
    leftA = -lMax/dMax/dMax         # parabola coef left from dMax
    rightA = -lMax/(lenV-dMax)**2   # parabola coef right from dMax
##  length of perpendicular    
    sLength =np.array([lMax+(x-dMax)**2*[leftA,rightA][x>=dMax] for x in dAlong])
    i = j%2                         # left or right side of straight line
##  perpendicular end points
    sX = -dY*sLength/lenV
    sY = dX*sLength/lenV
    if i: sX+=DF_X;sY+=DF_Y
    else: sX = DF_X-sX;sY = DF_Y - sY
    points = arcpy.Array([arcpy.Point(x,y) for x,y in zip(sX,sY)])
    pLine = arcpy.Polyline(points)
    return pLine

infc = "two_points"
array = arcpy.da.FeatureClassToNumPyArray(infc, ["SHAPE@X","SHAPE@Y"])
XS,XE = array["SHAPE@X"]; dX = XE-XS
YS,YE = array["SHAPE@Y"]; dY = YE-YS
DF_X = np.linspace(XS,XE,100)
DF_Y = np.linspace(YS,YE,100)
dAlong = np.array([x[0] for x in scipy.spatial.distance.cdist(zip(DF_X,DF_Y),[[XS,YS]])])
lenV = dAlong[-1]
lines = map(RotateExtend,range(10))
outfc = arcpy.GetParameterAsText(0)
arcpy.management.CopyFeatures(lines,outfc)

If you need more than 10 polylines change this line of code accordingly:

lines = map(RotateExtend,range(10))

edited body
Source Link
FelixIP
  • 23.3k
  • 3
  • 31
  • 62

This is nice geometry exercise and requires coding. To create a family of curves we can compute deviation from straight line using 2 randomly selected parameters; use parabola for smooth connection;transition; draw variable length perpendiculars to actual line and connect their end points:

enter image description here

Note that if we pick dMax at mid point of the line (25 in this case), we'll get symmetric 'wings'.

Output for 10 lines might look like this:

enter image description here

import numpy as np
import pandas as pd
import scipy
import random

def RotateExtend(j):
    iDmax = random.randint(10, 90)  
    dMax = DF.DISTANCE.at[iDmax]    # max deviation location (dMax)
    iLmax = random.randint(0, 30)   
    lMax = DF.DISTANCE.at[iLmax]    # max deviation itself
    leftA = -lMax/dMax/dMax         # parabola coef left from dMax
    rightA = -lMax/(lenV-dMax)**2   # parabola coef right from dMax
##  length of perpendicular    
    aList=[lMax+(x-dMax)**2*[leftA,rightA][x>=dMax] for x in DF.DISTANCE]
    DF["sLength"] = aList
    i = j%2                         # left or right side of straight line
##  perpendicular end points
    sX = -dY*DF.sLength/lenV
    sY = dX*DF.sLength/lenV
    if i: sX+=DF.X;sY+=DF.Y
    else: sX = DF.X-sX;sY = DF.Y - sY
    points = arcpy.Array([arcpy.Point(x,y) for x,y in zip(sX,sY)])
    pLine = arcpy.Polyline(points)
    return pLine

infc = "two_points"
array = arcpy.da.FeatureClassToNumPyArray(infc, ["SHAPE@X","SHAPE@Y"])
XS,XE = array["SHAPE@X"]; dX = XE-XS
YS,YE = array["SHAPE@Y"]; dY = YE-YS
DF = pd.DataFrame()
DF["X"] = np.linspace(XS,XE,100)
DF["Y"] = np.linspace(YS,YE,100)
DF["DISTANCE"] = scipy.spatial.distance.cdist(zip(DF.X,DF.Y),[[XS,YS]])
lenV = DF.DISTANCE.max()
lines = map(RotateExtend,range(10))
outfc = arcpy.GetParameterAsText(0)
arcpy.management.CopyFeatures(lines,outfc)

If you need more than 10 polylines change this line of code accordingly:

lines = map(RotateExtend,range(10))

This is nice geometry exercise and requires coding. To create a family of curves we can compute deviation from straight line using 2 randomly selected parameters; use parabola for smooth connection; draw variable length perpendiculars and connect their end points:

enter image description here

Note that if we pick dMax at mid point of the line (25 in this case), we'll get symmetric 'wings'.

Output for 10 lines might look like this:

enter image description here

import numpy as np
import pandas as pd
import scipy
import random

def RotateExtend(j):
    iDmax = random.randint(10, 90)  
    dMax = DF.DISTANCE.at[iDmax]    # max deviation location (dMax)
    iLmax = random.randint(0, 30)   
    lMax = DF.DISTANCE.at[iLmax]    # max deviation itself
    leftA = -lMax/dMax/dMax         # parabola coef left from dMax
    rightA = -lMax/(lenV-dMax)**2   # parabola coef right from dMax
##  length of perpendicular    
    aList=[lMax+(x-dMax)**2*[leftA,rightA][x>=dMax] for x in DF.DISTANCE]
    DF["sLength"] = aList
    i = j%2                         # left or right side of straight line
##  perpendicular end points
    sX = -dY*DF.sLength/lenV
    sY = dX*DF.sLength/lenV
    if i: sX+=DF.X;sY+=DF.Y
    else: sX = DF.X-sX;sY = DF.Y - sY
    points = arcpy.Array([arcpy.Point(x,y) for x,y in zip(sX,sY)])
    pLine = arcpy.Polyline(points)
    return pLine

infc = "two_points"
array = arcpy.da.FeatureClassToNumPyArray(infc, ["SHAPE@X","SHAPE@Y"])
XS,XE = array["SHAPE@X"]; dX = XE-XS
YS,YE = array["SHAPE@Y"]; dY = YE-YS
DF = pd.DataFrame()
DF["X"] = np.linspace(XS,XE,100)
DF["Y"] = np.linspace(YS,YE,100)
DF["DISTANCE"] = scipy.spatial.distance.cdist(zip(DF.X,DF.Y),[[XS,YS]])
lenV = DF.DISTANCE.max()
lines = map(RotateExtend,range(10))
outfc = arcpy.GetParameterAsText(0)
arcpy.management.CopyFeatures(lines,outfc)

If you need more than 10 polylines change this line of code accordingly:

lines = map(RotateExtend,range(10))

This is nice geometry exercise and requires coding. To create a family of curves we can compute deviation from straight line using 2 randomly selected parameters; use parabola for smooth transition; draw variable length perpendiculars to actual line and connect their end points:

enter image description here

Note that if we pick dMax at mid point of the line (25 in this case), we'll get symmetric 'wings'.

Output for 10 lines might look like this:

enter image description here

import numpy as np
import pandas as pd
import scipy
import random

def RotateExtend(j):
    iDmax = random.randint(10, 90)  
    dMax = DF.DISTANCE.at[iDmax]    # max deviation location (dMax)
    iLmax = random.randint(0, 30)   
    lMax = DF.DISTANCE.at[iLmax]    # max deviation itself
    leftA = -lMax/dMax/dMax         # parabola coef left from dMax
    rightA = -lMax/(lenV-dMax)**2   # parabola coef right from dMax
##  length of perpendicular    
    aList=[lMax+(x-dMax)**2*[leftA,rightA][x>=dMax] for x in DF.DISTANCE]
    DF["sLength"] = aList
    i = j%2                         # left or right side of straight line
##  perpendicular end points
    sX = -dY*DF.sLength/lenV
    sY = dX*DF.sLength/lenV
    if i: sX+=DF.X;sY+=DF.Y
    else: sX = DF.X-sX;sY = DF.Y - sY
    points = arcpy.Array([arcpy.Point(x,y) for x,y in zip(sX,sY)])
    pLine = arcpy.Polyline(points)
    return pLine

infc = "two_points"
array = arcpy.da.FeatureClassToNumPyArray(infc, ["SHAPE@X","SHAPE@Y"])
XS,XE = array["SHAPE@X"]; dX = XE-XS
YS,YE = array["SHAPE@Y"]; dY = YE-YS
DF = pd.DataFrame()
DF["X"] = np.linspace(XS,XE,100)
DF["Y"] = np.linspace(YS,YE,100)
DF["DISTANCE"] = scipy.spatial.distance.cdist(zip(DF.X,DF.Y),[[XS,YS]])
lenV = DF.DISTANCE.max()
lines = map(RotateExtend,range(10))
outfc = arcpy.GetParameterAsText(0)
arcpy.management.CopyFeatures(lines,outfc)

If you need more than 10 polylines change this line of code accordingly:

lines = map(RotateExtend,range(10))

Source Link
FelixIP
  • 23.3k
  • 3
  • 31
  • 62
Loading