Solve a line segment using barycentric coordinates.
()
| 425 | |
| 426 | // Solve a line segment using barycentric coordinates. |
| 427 | func (simplex *B2Simplex) Solve2() { |
| 428 | w1 := simplex.M_vs[0].W |
| 429 | w2 := simplex.M_vs[1].W |
| 430 | e12 := B2Vec2Sub(w2, w1) |
| 431 | |
| 432 | // w1 region |
| 433 | d12_2 := -B2Vec2Dot(w1, e12) |
| 434 | if d12_2 <= 0.0 { |
| 435 | // a2 <= 0, so we clamp it to 0 |
| 436 | simplex.M_vs[0].A = 1.0 |
| 437 | simplex.M_count = 1 |
| 438 | return |
| 439 | } |
| 440 | |
| 441 | // w2 region |
| 442 | d12_1 := B2Vec2Dot(w2, e12) |
| 443 | if d12_1 <= 0.0 { |
| 444 | // a1 <= 0, so we clamp it to 0 |
| 445 | simplex.M_vs[1].A = 1.0 |
| 446 | simplex.M_count = 1 |
| 447 | simplex.M_vs[0] = simplex.M_vs[1] |
| 448 | return |
| 449 | } |
| 450 | |
| 451 | // Must be in e12 region. |
| 452 | inv_d12 := 1.0 / (d12_1 + d12_2) |
| 453 | simplex.M_vs[0].A = d12_1 * inv_d12 |
| 454 | simplex.M_vs[1].A = d12_2 * inv_d12 |
| 455 | simplex.M_count = 2 |
| 456 | } |
| 457 | |
| 458 | // // Possible regions: |
| 459 | // // - points[2] |
no test coverage detected