Finding intersection point of a convex polygon edge and a moving point(vector)

3658
1
03-08-2014 03:25 PM
Abdelarqub
New Contributor
Hello,
How to calculate an intersection point of convex hull edge and a moving point leaving that hull? where all of the hull vertices are
known, the speed and the direction angle of the moving point are also known. An illustration is attached

Thanks,
Abdel
0 Kudos
1 Reply
XanderBakker
Esri Esteemed Contributor
Hi Abdel,

I suppose the speed would not matter as long as the line from point Q extent outside the convex hull polygon. So with that in mind, take a look at the Python code below. It works with a list of points (hard coded in this snippet) and an angle (could be arithmetic or geographic). The following steps are carried out:


  • the points are added to a multipoint object

  • the convex hull polygon is calculated from the multipoint

  • the boundary is extracted from the polygon

  • the centroid of the polygon is in this case used for point Q

  • to be sure that the line starting in point Q will exit the polygon, I use a "large" length (so no speed used)

  • the point Q2 is determined using the length and angle

  • a line is created using Q and Q2

  • the line is intersected with the boundary to obtain the desired intersection point

  • the X and Y of the resulting point is printed


def main():
    import arcpy, os

    # input points
    pnts = [[200,800],[100, 500],[300,100],[1000,200],[1200,700]]

    # input angle
    angle_geo = 100 # geographic degrees
    angle_ari = arithmatic_geographic(angle_geo) # = 350 in arithmetic degrees

    # create a multi point from input points
    arr_mp = arcpy.Array()
    for p in pnts:
        pnt = arcpy.Point(p[0], p[1])
        arr_mp.add(pnt)
    mp = arcpy.Multipoint(arr_mp)

    # determine convex hull of input points
    pol = mp.convexHull()

    # get boundary of convex hull polygon
    bnd = pol.boundary()

    # let's take centroid for Q
    q = pol.centroid

    # determine line length (enough to intersect boundary)
    length = pol.extent.width + pol.extent.height

    # create second point (Q2)
    dx, dy = LengthDir(length, angle_ari)
    q2 = arcpy.Point(q.X + dx, q.Y + dy)

    # make line of Q and Q2
    arr_line = arcpy.Array()
    arr_line.add(q)
    arr_line.add(q2)
    line = arcpy.Polyline(arr_line)

    # intersect (other, dimension), dimension can be 1 or 2
    pnt_int = line.intersect(bnd, 1) # returns mp

    # print resulting intersection coordinates
    for p in pnt_int:
        print p.X, p.Y

def arithmatic_geographic(angle):
    new_angle = angle + 270
    while new_angle > 360:
        new_angle -= 360
    return 360 - new_angle


def LengthDir(length, angle):
    import math
    radian_angle = angle * math.pi / 180
    return length * math.cos(radian_angle), length * math.sin(radian_angle)

if __name__ == '__main__':
    main()


If you can explain what your input data looks like, the code can be adapted.

Kind regards,

Xander
0 Kudos