Take the 2-minute tour ×
Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. It's 100% free, no registration required.

I have 3 parallel line segments (say AB, CD, and EF are line segments and they are nearly horizontal) lay on 2 slanted planes which have been intersected through the CD. If I projected all the line segments on to the 2D horizontal plane; then distance (in 2D) between projected AB & CD (say d1) and CD & EF (say d2) are not the same. So, I want to maintain d1=d2.

For that, if d1>d2 then I have to move EF away from the center line otherwise I have to move AB.

But I should move either the line along the steepest direction of corresponding plane i.e. either ABCD or CDEF. So that new line can be kept on the same ABCD (or CDEF) plane. And also can be persevered the parallism as well.

Also, I cannot exactly say that all the lines (AB, CD and EF) are pointing into a same/opposit direction. Sometimes one line might be 180 degree opposite to another. Also, I have vector3 to do this in c++.

So, please let me know a concrete way to do this as I got some wrong answer on my way. Thanks in advance.

share|improve this question
add comment

1 Answer 1

up vote 0 down vote accepted

Building on my answer to a related previous question, I'm putting an answer I sketched in chat into a proper form.

The key idea behind this whole solution is the fact that you can use the dot product between a vector of length $1$ and another vector to compute the length of the projection of the second vector onto the first. I imagine this as computing the component of a given vector into a given direction.

Computing the distances

The first thing you need is a vector which has length 1 and lies in your horizontal plane and is orthogonal to the direction of your three lines. I'll call this vector $u$. In general, you can compute such a vector using the cross product:

\begin{align*} u' &= h\times (C-D) \\ u &= \frac{u'}{\lVert u'\rVert} = \frac{1}{\sqrt{u'\cdot u'}}u' \end{align*}

Here $h$ is the normal of your horizontal plane, and $C-D$ is the direction vector of your line $CD$.

If $h$ has simple coordinates like $(0,0,1)$, then you'd have $C-D=(x,y,z)$ for some numbers $x,y,z\in\mathbb R$. In that case you could avoid actually computing the cross product, and simply write $u'=(y,-x,0)$. You'd still have to normalize as above, though.

So now you have this vector $u$, you can use it to measure distances between projected lines:

\begin{align*} d_1 &= \left\lvert u\cdot (A - C)\right\rvert \\ d_2 &= \left\lvert u\cdot (E - C)\right\rvert \end{align*}

Moving the line

Now you have to see which of these numbers is the smaller one, as that indicates which line you want to change. For now I'll assume that $d_1<d_2$; the other case works in the same way by simply exchanging corresponding variables.

Now you know that you want to move $AB$ in such a way that its distance scales by a factor of $\frac{d_2}{d_1}$. As you require the movement to go in the direction of “steepest incline”, you probably want the displacement vector to be orthogonal to the direction of the three original lines. (In the case of not really horizontal lines, there would be a difference, but I take it that you still want to move “directly” away from $CD$.) So what we do is we take the vector pointing from $C$ to $A$, and remove from that vector the component in direction $D-C$.

\begin{align*} v = (A-C) - \frac{(A-C)\cdot(D-C)}{(D-C)\cdot(D-C)}(D-C) = (A-C) - \left((A-C)\cdot\frac{D-C}{\lVert D-C\rVert}\right)\frac{D-C}{\lVert D-C\rVert} \end{align*}

The rightmost version in the above formulation shows that I'm thinking about a Version of the vector $D-C$ which has been normalized, i.e. scaled to unit length. The version to the left demonstrates how you can obtain the same result without actually computing the square root. So the left version is the one I'd implement, but the right version might be easier to comprehend.

The vector $v$ as computed above will point from any point on the infinite line $CD$ to the point on the infinite line $AB$ along a path of steepest incline.

So now you can take this vector $v$ and use it to compute the displacement you need.

\begin{align*} v' &= \frac{d_2}{d_1} v - v = \left(\frac{d_2}{d_1} - 1\right)v \\ A' &= A + v' \\ B' &= B + v' = A' + (B - A) \end{align*}

Now you have the points of the new line $A'B'$ which lies in the plane $ABCD$, and which will have the desired distance in the projection onto the horizontal plane.

share|improve this answer
    
thank you. for the line EF, does the v' = (d2/d1-1)v where v is calculated with E, C, D and E' = E + v' and F' = F + v'? I applied as same, but my lines donot make similar distances... thinking the error is my code.. –  gnp Dec 5 '12 at 2:29
    
@user1199463, for $EF$ you set $w=(E-C)-\frac{(E-C)\cdot(D-C)}{(D-C)\cdot(D-C)}(D-C)$ and $w'=\frac{d_1}{d_2}w-w$ from which you get $E'=E+w'$. –  MvG Dec 5 '12 at 6:51
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.