| 105 | } |
| 106 | |
| 107 | bool vertexLineIntersect(float Ax, float Ay, float Bx, float By, float Cx, float Cy, float Dx, float Dy, float* T) |
| 108 | { |
| 109 | float distAB, theCos, theSin, newX; |
| 110 | |
| 111 | // FAIL: Line undefined |
| 112 | if ((Ax == Bx && Ay == By) || (Cx == Dx && Cy == Dy)) |
| 113 | return false; |
| 114 | |
| 115 | // Translate system to make A the origin |
| 116 | Bx -= Ax; |
| 117 | By -= Ay; |
| 118 | Cx -= Ax; |
| 119 | Cy -= Ay; |
| 120 | Dx -= Ax; |
| 121 | Dy -= Ay; |
| 122 | |
| 123 | // Length of segment AB |
| 124 | distAB = sqrtf(Bx * Bx + By * By); |
| 125 | |
| 126 | // Rotate the system so that point B is on the positive X axis. |
| 127 | theCos = Bx / distAB; |
| 128 | theSin = By / distAB; |
| 129 | newX = Cx * theCos + Cy * theSin; |
| 130 | Cy = Cy * theCos - Cx * theSin; |
| 131 | Cx = newX; |
| 132 | newX = Dx * theCos + Dy * theSin; |
| 133 | Dy = Dy * theCos - Dx * theSin; |
| 134 | Dx = newX; |
| 135 | |
| 136 | // FAIL: Lines are parallel. |
| 137 | if (Cy == Dy) |
| 138 | return false; |
| 139 | |
| 140 | // Discover the relative position of the intersection in the line AB |
| 141 | *T = (Dx + (Cx - Dx) * Dy / (Dy - Cy)) / distAB; |
| 142 | |
| 143 | // Success. |
| 144 | return true; |
| 145 | } |
| 146 | |
| 147 | } |
no outgoing calls
no test coverage detected