Pseudo- EPA (expanding polytope algorithm) to find the embedding direction and depth of overlapping convex graphs

Source: Internet
Author: User
Tags dashed line modulus

Reference: http://www.dyn4j.org/2010/05/epa-expanding-polytope-algorithm/

In the previous chapter, the GJK can be used to determine whether the two convex figures overlap, and the EPA can overlap its embedded depth and direction.

Minkowski of two convex graphs if the origin is included, then two convex shapes overlap. The distance from one edge to the origin of the Minkowski is the minimum embedding depth of two graphs, and the vertical direction of the edge is the minimum embedding direction of the two graphs.

After using GJK to obtain the simplex form containing the origin, the EPA expands the simplex, allowing the expanded simplex to contain the edge of the Minkowski with the smallest distance from the original point.

However, it is sufficient to require that one edge be embedded in depth and direction, and there is no need to preserve the entire extended simplex. So I changed it into this:

, assuming that the ellipse is the shape of the Minkowski, ABC is the simplex obtained at the end of the GJK, and the point O is the origin point.

The point DA and DB closest to the origin of the AC and BC are obtained first, and the distance between the AC and BC to the origin is judged by the modulus length of the DA and DB.

If AC is closer to the origin than BC, discard point B and use points A and C as new simplex vertices a ' and B ', using the direction of the Vector da as the new search direction.

Otherwise, discard point a (as shown), use point B and point C as the new simplex vertex a ' and B ', using vector db as the new search direction.

Then, use the same getsupportpoint function as in GJK to find the new C '.

Now, point A (or Point B) and point C are projected into the search direction, and the difference is Det (shown in the blue dashed line).

If the DET is small enough, then it is found that a Minkowski is as close as possible to the origin of the edge, at this time to return AB on the nearest point to the origin of the vector Vec, the direction of the VEC is embedded in the direction, VEC's modulus is the minimum length of embedding distance.

If the DET is too large, repeat the above process.

Proc getpenetrationvector* (S1, s2:sprite2d, SA, SB, sc:vector2d, Tolerance:float32 = 0.2): vector2d =    var        a = s A        B = SB        c = SC        dir:vector2d    while true:        let            da = Getclosestpointtoorigin (A, c)            db = Getclos Estpointtoorigin (b, c)        if Da.sqlen > Db.sqlen:            a = b            b = c            dir = db.norm ()        else:            B = c
   dir = Da.norm ()        C = getsupportpoint (S1, S2, dir)        if (c-a) * dir <= tolerance:            return Getclosestpoint Toorigin (A, B)

The method of finding the closest point to the origin from the line segment is to project the origin onto the segment.

Proc Getclosestpointtoorigin (A, b:vector2d): vector2d =    let        ab = Norm (b-a)        ao = a.negate ()    return a + AB * (AB * ao)

 

The final effect, the white line represents the vector of the minimum length required to push the polygon away from the ellipse

Pseudo- EPA (expanding polytope algorithm) to find the embedding direction and depth of overlapping convex graphs

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.