Compute contact points for edge versus circle. This accounts for edge connectivity.
(manifold *B2Manifold, edgeA *B2EdgeShape, xfA B2Transform, circleB *B2CircleShape, xfB B2Transform)
| 7 | // Compute contact points for edge versus circle. |
| 8 | // This accounts for edge connectivity. |
| 9 | func B2CollideEdgeAndCircle(manifold *B2Manifold, edgeA *B2EdgeShape, xfA B2Transform, circleB *B2CircleShape, xfB B2Transform) { |
| 10 | manifold.PointCount = 0 |
| 11 | |
| 12 | // Compute circle in frame of edge |
| 13 | Q := B2TransformVec2MulT(xfA, B2TransformVec2Mul(xfB, circleB.M_p)) |
| 14 | |
| 15 | A := edgeA.M_vertex1 |
| 16 | B := edgeA.M_vertex2 |
| 17 | e := B2Vec2Sub(B, A) |
| 18 | |
| 19 | // Barycentric coordinates |
| 20 | u := B2Vec2Dot(e, B2Vec2Sub(B, Q)) |
| 21 | v := B2Vec2Dot(e, B2Vec2Sub(Q, A)) |
| 22 | |
| 23 | radius := edgeA.M_radius + circleB.M_radius |
| 24 | |
| 25 | cf := MakeB2ContactFeature() |
| 26 | cf.IndexB = 0 |
| 27 | cf.TypeB = B2ContactFeature_Type.E_vertex |
| 28 | |
| 29 | // Region A |
| 30 | if v <= 0.0 { |
| 31 | P := A |
| 32 | d := B2Vec2Sub(Q, P) |
| 33 | dd := B2Vec2Dot(d, d) |
| 34 | if dd > radius*radius { |
| 35 | return |
| 36 | } |
| 37 | |
| 38 | // Is there an edge connected to A? |
| 39 | if edgeA.M_hasVertex0 { |
| 40 | A1 := edgeA.M_vertex0 |
| 41 | B1 := A |
| 42 | e1 := B2Vec2Sub(B1, A1) |
| 43 | u1 := B2Vec2Dot(e1, B2Vec2Sub(B1, Q)) |
| 44 | |
| 45 | // Is the circle in Region AB of the previous edge? |
| 46 | if u1 > 0.0 { |
| 47 | return |
| 48 | } |
| 49 | } |
| 50 | |
| 51 | cf.IndexA = 0 |
| 52 | cf.TypeA = B2ContactFeature_Type.E_vertex |
| 53 | manifold.PointCount = 1 |
| 54 | manifold.Type = B2Manifold_Type.E_circles |
| 55 | manifold.LocalNormal.SetZero() |
| 56 | manifold.LocalPoint = P |
| 57 | manifold.Points[0].Id.SetKey(0) |
| 58 | manifold.Points[0].Id.IndexA = cf.IndexA |
| 59 | manifold.Points[0].Id.IndexB = cf.IndexB |
| 60 | manifold.Points[0].Id.TypeA = cf.TypeA |
| 61 | manifold.Points[0].Id.TypeB = cf.TypeB |
| 62 | manifold.Points[0].LocalPoint = circleB.M_p |
| 63 | return |
| 64 | } |
| 65 | |
| 66 | // Region B |
no test coverage detected