Extend Length of Line in 3D Space (Find New End Point)

Mikester4411

New member
Joined
Sep 26, 2020
Messages
3
Hi, I have 2 things, both doing similar things with similar end goals;

1. How would I extend the length of a line in 3D space, knowing only the start and end point of an original line, and the length value to add, and finish with a new end point in 3D space ending where the line extends to with the added length, like in the attached picture

AddLength.jpg (Hit Location is the original End Location)

2. Instead of taking in a start and already pre-determined end location, how would I use just the start location and a rotation, then extending a line from the start location in the direction of the rotation by the length of the 'Add Length' value, and outputting the point at the end of the line in 3D space

What would their equations be, and how would I do it in a simpler step-by-step way
Thanks!
 
1st of all a line has no starting point and an end point as it goes in both directions for ever.

A line segment has a start and finish point.

Given two points on a line can you find other points? Maybe the midpoint, the one quarter point, twice the length, 1 1/2 times the original length, etc. Can you figure out how to find the equation of the line?
 
Hi, I have 2 things, both doing similar things with similar end goals;

1. How would I extend the length of a line in 3D space, knowing only the start and end point of an original line, and the length value to add, and finish with a new end point in 3D space ending where the line extends to with the added length, like in the attached picture

View attachment 21890 (Hit Location is the original End Location)

2. Instead of taking in a start and already pre-determined end location, how would I use just the start location and a rotation, then extending a line from the start location in the direction of the rotation by the length of the 'Add Length' value, and outputting the point at the end of the line in 3D space

What would their equations be, and how would I do it in a simpler step-by-step way
Thanks!
The best thing to do is to learn about vectors. Have you? They are especially useful if you are planning to do any programming, which this looks like.
 
Sorry, yeah, I should've been a bit more clear, this is for programming, I know about vectors, it's just understanding how to figure out what equations work for what I'm trying to do.

I'm doing a line trace/raycast from the start point to the original end point, but I want to be able to use them start and end point vectors, then add length to the line segment by moving the end point further up the line (amount depending on the float input) making sure the line stays straight, and outputting the new end point vector to use for the line trace.

As far as I know, there's no way to find out any other points on the line without multiple hit points (where the line intersects an object in the game world) on the line trace.
 
Hi, I have 2 things, both doing similar things with similar end goals;

1. How would I extend the length of a line in 3D space, knowing only the start and end point of an original line, and the length value to add, and finish with a new end point in 3D space ending where the line extends to with the added length, like in the attached picture

View attachment 21890 (Hit Location is the original End Location)

2. Instead of taking in a start and already pre-determined end location, how would I use just the start location and a rotation, then extending a line from the start location in the direction of the rotation by the length of the 'Add Length' value, and outputting the point at the end of the line in 3D space

What would their equations be, and how would I do it in a simpler step-by-step way
Thanks!
1. How would I extend the length of a line in 3D space, knowing only the start and end point of an original line, and the length value to add, and finish with a new end point in 3D space ending where the line extends to with the added length, like in the attached picture
Suppose the start location is S(xS, yS) and the hit location is H(xH, yH)

What would be the length of the line SH (joining S & H and as a function of the parameters defined above)?

The equation of the line (joining S & H) is:

(y - yS) / (yH - yS) = (x - xS) / (xH - xS)​

Suppose the new point is N (xN, yN). Then it must satisfy:

(yN - yS) / (yN - yS) = (xN - xS) / (xN - xS) .... (1)​
And
it has to satisfy the "Length" equation. From equation (1) above and the new length equation - you should be able to calculate xN and yN.​

Please share your work if you need further clarification/s.
 
The problem asked about 3 dimensions but Subhotosh Kahn appears to be speaking about a line in two dimensions instead. In 3 dimensions it is simplest to use "parametric equations" with x, y, and z each depending on the single parameter, t.

If the original starting point is \(\displaystyle (x_0, y_0, z_0)\) and the original ending point is \(\displaystyle (x_1, y_1, z_1)\) then the line can be written as \(\displaystyle x= (x_1- x_0)t+ x_0\), \(\displaystyle y= (y_1- y_0)t+ y_0\), \(\displaystyle z= (z_1- z_0)t+ z_0\).

(It is easy to see that this is correct. First because each of the three equations is "linear", it describes a straight line. When t= 0, \(\displaystyle (x, y, z)= (x_0, y_0, z_0)\) and when when t= 1, \(\displaystyle (x, y, z)= ((x_1- x_0)(1)+ x_0, (y_1- y_0)(1)+ y_0, (z_1- z_0)+ z_0)\)\(\displaystyle = (x_1- x_0+ x0, y_1- y_0+ y_0, z_1- z_0+ z_0)= (x_1, y_1, z_1)\).)

The length of that line segment is \(\displaystyle L1= \sqrt{(x_1- x_0)^2+ (y_1- y_0)^2+ (z_1- z_0)^2}\). To extend the line so that its length is \(\displaystyle L2\) we just need to take \(\displaystyle t= \frac{L2}{L1}\) so that the new endpoint is \(\displaystyle x= (x_1- x_0)\frac{L2}{L1}+ x_0\), \(\displaystyle y= (y_1- y_0)\frac{L2}{L1}+ y_0\), and \(\displaystyle z= (z_1- z_0)\frac{L2}{L1}+ z_0\).
 
Sorry, yeah, I should've been a bit more clear, this is for programming, I know about vectors, it's just understanding how to figure out what equations work for what I'm trying to do.

I'm doing a line trace/raycast from the start point to the original end point, but I want to be able to use them start and end point vectors, then add length to the line segment by moving the end point further up the line (amount depending on the float input) making sure the line stays straight, and outputting the new end point vector to use for the line trace.

As far as I know, there's no way to find out any other points on the line without multiple hit points (where the line intersects an object in the game world) on the line trace.

Call the player P, original end point E, and new end point N.

Find vector PE, and its length |PE|. Divide the desired extension length L by |PE|, and multiply vector PE by that quantity. Then add that vector to the location vector of E, to get N.

N = E + (L/|PE|)*PE​
 
Top