0
\$\begingroup\$

I'm trying to lengthen a line, by a certain amount. I want to apply the modification to both points on the line, expanding it in both directions. without moving it from it's current position (center point expansion would be acceptable, but I'n not sure how to apply it).

Exact details:

Line:

Point 1 [X = 1 , Y = 4], Point 2 [X = -1, Y = 6]

Line Normalized Vector: V = [X = -0.707106, Y = 0.707106]

Expand by: E = 1

So the result I'm looking for is

New Line = [ 1.707 , 4.707 ] ~ [ -1.707 , 6.707 ]

My problem happens when I multiply Point2[X] + ((0-V[x])*E) = - 0.292

Can someone give a SIMPLE example. Psudo code, is great!

I know it is because I'm crossing the zero line, but I'm sure there's a better way to do this than testing if the point is greater than zero or less than zero.

\$\endgroup\$
1
\$\begingroup\$
StartX, StartY <---> EndX, EndY
Normalised = -0.707, 0.707
Inverse Normalised = 0.707, -0.707

Extend in both directions by E
NewStartX = StartX + (E * InvNormX)
NewStartY = StartY + (E * InvNormY)

NewEndX = EndX + (E * NormX)
NewEndY = EndY + (E * NormY)

ie, using your numbers above it would be

NewStartX = 1 + (E * InvNormX) = 1 + (1 * 0.707) = 1.707
NewStartY = 4 + (E * InvNormY) = 4 + (1 * -0.707) = 3.293

NewEndX = -1 + (E * NormX) = -1 + (1 * -0.707) = -1.707
NewEndY = 6 + (E * NormY) = 6 + (1 * 0.707) = 6.707
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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