![]() % because that's what I'll need in a minute. Trot = % the t vector, rotated 90 degrees ![]() S = % first cross productĪnd here's the more idiomatic, minimal operations, version: function v = findVec(A, B, C) % a vector v in the xy-plane that is perpendicular to AB, and points % Given points A,B,C in the xy-plane, C not on the line AB, find Here's something like an algorithm, written in very explicit Matlab function v = findVec(A, B, C) You said not, but in practice, I've often found such things annoying. You have to decide whether that matters to you. It also has a downside: if $C$ is very close to the line $AB$, the magnitude of the resulting vector gets very small. But it has one advantage: there's no branching, which can be helpful on some highly-parallel architectures (or at least this used to be the case). Is this a winning algorithm? I haven't counted the operations in the other one. You needn't compute the $z$-component (it'll be zero), so you end up doing a total of $6$ multiplies and $3$ subtracts, plus the 6 subtractions to compute $u$ and $t$ in the first place. Then you compute $v = t \times s$, and this vector will point in the right direction. Īn alternative approach is to compute $s = u \times t$ (in 3-space), which seems bad because it's a cross-product, which looks like 2 multiplies and a subtraction for each term.but you only need to compute the "z" term because the other two are always zero. If it's $0$, then $C$ is actually collinear with $A$ and $B$, which is kind of a free sanity-check that your inputs were valid. If this turns out positive, then $u$ and $v_1$ point into the same halfplane, and your answer is $v_1$ if it's negative, your answer is $v_2$. The vectors $v_1$ and $v_2$ are indeed both nonzero and perpendicular to $L$, and also point in opposite directions, so one of them has to be a "good" one. I know that there are two orthogonal vectors to $T$: $\vec$? I really don't care about the magnitude of the resulting vector. ![]() Given three points $A$, $B$ and $C$, that are not colinear, I want to find the vector $v$ which is perpendicular to the line $L$ that passes from $A$ and $B$ AND points to the half-plane created by $L$ that $C$ lies on. Given any vector ( a, b, c), with a, b, c 0, a fast way to find a perpendicular vector is to consider ( b, a, 0) ( a, b, c) ( b, a, 0) a b b a 0 0 or other similar combination of the components as for example ( c, 0, a) or ( 0, c, b). ![]()
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |