Home computickets How to find a point on the segment?

How to find a point on the segment?

Author

Date

Category

I have a segment with known coordinates of the ends. On this segment there is a point. I know the distance from the beginning of the segment to this point. I need to find the coordinates of this point. How to find these coordinates?

Example: there are 2 points A (3.3) and in (6.4). Cut length approximately 3.16. And is there a point with (?,?) On the segment. How to find coordinates if from a to C = 1.8 ???


Answer 1, Authority 100%

Algorithm without code (pretty elementary):

We have:
Two points a , b ; len – distance from point and to the desired point C

Full_len = | B - A | // Length of the vector connecting two points == Cut length
C = A + (B - A) * (LEN / FULL_LEN)

Addition of vectors and multiplication by number – obvious operations.


Answer 2, Authority 80%

There is a segment ab with coordinates A (Xa, Ya) and B (XB, YB)
It is required to find the coordinates of the C (XC, YC) section lying on the AB section at the distance RAC from the A point.

Rab = SQRT ((XB - XA) ^ 2 + (YB - Ya) ^ 2)
K = RAC / RAB
XC = XA + (XB - XA) * k
YC = Ya + (YB - Ya) * k

Notation:
f ^ n – the construction of f to the degree n , in our case (first) f will be XB - XA and N will 2
sqrt (f) – square root from f in our case f will (XB - XA ) ^ 2 + (YB - Ya) ^ 2
f / n – division f on n , in our case, F will be RAC and N will Rab
f * n – multiplication f on n , in our case (first) f Will XB - XA and N will k .


Answer 3, Authority 10%

nodet – point end end, in your case Point b
nodef – point beginning of the vector, in your case Point a

dx = nodet.x - nodef.x
dy = nodet.y - nodef.y
DZ = NODET.Z - NODEF.Z
R = Math.SQRT (dx ** 2 + dy ** 2 + dz ** 2)
xx = dx * (STEP / R)
YY = DY * (STEP / R)
zz = dz * (STEP / R)
newnode = node (nodef.x + xx, nodef.y + yy, nodef.z + zz)

newnode – new point at a specified distance

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions