Why doesn't this implementation of Jarvis' March (“Gift wrapping algorithm”) work?

后端 未结 2 1085
礼貌的吻别
礼貌的吻别 2021-01-31 12:11

I\'m trying to implement Jarvis\' algorithm for finding the convex hull of a set of points, but for some reason it doesn\'t work. This is my implementation:

proc         


        
2条回答
  •  暖寄归人
    2021-01-31 12:32

    The loop adds using this line of code:

    aHull.Add(vPointOnHull);
    

    vPointOnHull is only assigned in these lines:

    vPointOnHull := Self.LeftMostPoint;
    vPointOnHull := vEndpoint;
    

    You already explained that LeftMostPoint is added correctly, so the repeat must come from vEndPoint, which is assigned in these lines:

    vEndpoint := Self.Point[0];
    vEndpoint := Self.Point[I];
    

    So I guess the last assignment (which is in the below if statement), is never reached.

      if Orientation(vPointOnHull,vEndpoint,Self.Point[I]) = LeftHandSide then
        vEndpoint := Self.Point[I];
    

    --jeroen

提交回复
热议问题