mathwolfram-mathematicamathematica-8

How to know 4 nodes (in one line) have same directions (or not)


If I have 4 nodes on a line, for example:

It is clear that vector AB has the same direction with vector CD, or in other words, vector BA has the same direction with vector DC.

I know it is simple, that in this case we just calculate delta x and then divided by each length.

Is there any common technique and in a "straight-way fashion"?

For example by comparing the gradients (which is in this case, it would be still valid, since both gradients are zero, but if the coordinates are conversed, the computation will be error, since the gradients cannot be computed by dividing by zero).

Thanks in advance.


Solution

  • If you want to know whether AB has the same orientation as CD, compute the dot product (B-A)*(D-C). It will be positive if they point in the same direction, negative if they point in opposite directions, and zero if one of the vectors is zero (or otherwise perpendicular to the other, but you assumed collinear points so that can't happen).