Frage

This seems like such an easy problem yet I struggle finding a solution. If I have a single line (vector) and know it's start and end points, how can I adjust the locations of the points so that the line becomes longer or shorter without actually affecting it's slope or where it crosses on the screen?

Example: The points of a slanted line are: (3, 2), (8, 12) -- Now I want to stretch the line so that it crosses 25 on the Y axis while retaining its overall position and slope, and perhaps also want the other end to stretch below 0. So each end needs to be scaled a bit.

Is there a simple math formula for achieving this with diagonal lines? It's easy with straight lines.

War es hilfreich?

Lösung

You can use parametric equation of line:

X = X0 + t * (X1 - X0)
Y = Y0 + t * (Y1 - Y0)

where (X0, Y0) is start point, (X1, Y1) is end point of line segment, and t is parameter (it ranges 0..1 for inner points of segment).

For you example - solve 2+(12-2)*t=25, find t, and calc X for this t value

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top