Find 3D point along the line at given distance

In summary, the conversation discusses finding the coordinates of a third point on a line, given two known points and a distance ratio. The suggested approach involves obtaining the equation of the line formed by the two points, then using that to find the desired point. There is some discussion about a potential error in the code and how to test for colinearity.
  • #1
catalin.drago
10
0
Hello,

I have asked this question already but have not been able to get conclusive answer.

I have a problem and please let me know if my solution is correct.

I have a known point, at location A(x1,y1,z1) and the point B(x2,y2,z2) and I would like to find the coordinates of a third point C(x3,y3,z3) that is located on the line AB, and the distance AC is 1.2 times greater then AB.

So, my idea is to obtain the equation of the line formed by points A and B. The direction of AB is (x2-x1, y2-y1, z2-z1), so the equation of the line is:

x = x1-(x2-x1)*t;

y = y1-(y2-y1)*t;

z = z1-(z2-z1)*t;

Distance AB is sqrt( (x2-x1)^2 + (y2-y1)^2 + (z2-z1)^2). KNOWN

Distance AC is sqrt( (x3-x1)^2 + (y3-y1)^2 + (z3-z1)^2). UNKNOWN

I can replace the x, y, z points determined for the line equation in the distance AC, and the result should be 1.2 times greater then the distance AB.

So, sqrt( (x1-(x2-x1)*t-x1)^2 + (y1-(y2-y1)*t-0)^2 + (z1-(z2-z1)*t-0)^2) = 1.2 * dist(AB).

I find t from here, solving the quadratic equation and I obtain the coordinates of the point by replacing the t in the equation of the line.

Is this correct?

Thank you for your time.
 
Mathematics news on Phys.org
  • #2
Hey catalin.drago and welcome to the forums.

With regards to your parameterization, you should have the parametrization x = a + (b-a)t instead of x = a - (b-a)t if your direction is along the vector (b-a) instead of in the reverse.

Basically you want to find t that corresponds to the AB and then plug in t' = 1.2*t and then calculate the length of t' * ||n|| where n is your direction vector used for your line: in the above n = (b-a) but you can normalize this (and I suggest you do to make things easier).

With regards to getting the value of t recall that when t = 0 you get <x1,y1,z1> = A and then for t you get <x1,y1,z1> + n*t = B but since n and A are known you can just get n*t = B - A and since ||n|| = 1 then t = ||B - A||.
 
  • #3
Thank you for the reply.

So far I came up with the code below. I tried to verify the colinearity condition with the cross product of the vectors (P3-P1) and (P2-P1), but I don't get zero in all cases.

What am I doing wrong?

norm = sqrt((P2(1,1) - P1(1))^2 + (P2(1,2) - P1(2))^2 + (P2(1,2) - P1(1))^2);

P3(1) = P1(1) + ((P2(1) - P1(1)) /norm) * rangeRatio;
P3(2) = P1(2) + ((P2(2) - P1(2)) /norm) * rangeRatio;
P3(3) = P1(3) + ((P2(3) - P1(3)) /norm) * rangeRatio;

I have a point P1, and a point P2 and I would like to find a point P3 on the line of P1-P2, where dist P1-P3 is rangeRatio greater then the distance P1-P2

Do you have any idea where I go wrong?

P.S. It's Matlab code, so P1(1) is x, P1(2) is y, and P1(3) is z.

Thank you.
 
  • #4
catalin.drago said:
Thank you for the reply.

So far I came up with the code below. I tried to verify the colinearity condition with the cross product of the vectors (P3-P1) and (P2-P1), but I don't get zero in all cases.

What am I doing wrong?

norm = sqrt((P2(1,1) - P1(1))^2 + (P2(1,2) - P1(2))^2 + (P2(1,2) - P1(1))^2);

P3(1) = P1(1) + ((P2(1) - P1(1)) /norm) * rangeRatio;
P3(2) = P1(2) + ((P2(2) - P1(2)) /norm) * rangeRatio;
P3(3) = P1(3) + ((P2(3) - P1(3)) /norm) * rangeRatio;

I have a point P1, and a point P2 and I would like to find a point P3 on the line of P1-P2, where dist P1-P3 is rangeRatio greater then the distance P1-P2

Do you have any idea where I go wrong?

P.S. It's Matlab code, so P1(1) is x, P1(2) is y, and P1(3) is z.

Thank you.

Don't divide by the norm! Think about having range ratio = 1. If you don't divide by the norm you will get P2 as expected.
 
  • #5
Thank you for the reply.
I have implemented the code without division by norm, and I have tested the colinearity by applying the cross product on MB * MA, and by checking the slope between the MB and MA (for e.g.: (y1 - y2) * (x1 - x3) - (y1 - y3) * (x1 - x2) should be zero is all three points are colinear).
When I apply the cross product one axis is 0 and the rest very close to 0 (like x= 0 y= 0.005 and z = 0.02) and very rare I get all axis values equal to 0.
The same happens also with the slope computation. Instead of getting always 0, I sometimes get values like 0.03 or 0.007.
DO you have any idea why?
Is it normal?
Or can it be a tolerated error?
 
  • #6
How many decimal places are you keeping as you do the calculations? It is typically a good idea to keep one or two more decimal places in each calculation than you want in the final answer, then round off at the end. Otherwise, "round off error" can build up from calculation to calculation.
 
  • #7
Hello,
I tried rounding to 2 decimals and i still get in some cases non colinearity.
This is my code:

rangeRatio = 1.114;

norm = sqrt((P2(1) - P1(1))^2 + (P2(2) - P1(2))^2 + (P2(3) - P1(3))^2);

P3(1) = P1(1) + ((P2(1,1) - P1(1)) /norm) * rangeRatio;
P3(2) = P1(2) + ((P2(1,2) - P1(2)) /norm) * rangeRatio;
P3(3) = P1(3) + ((P2(1,3) - P1(3)) /norm) * rangeRatio;

I tried also norm = 1, and i get slightly different results but still not always colinear.

Thank you
 
  • #8
To test it out I suggest using range ratio = 1. You then should get P2 exactly. If not, there is a bug in your code.

Your last post has P2(1,k). Why the extra index?

Do not divide by norm!
 
  • #9
Hello,

I have tested with ratio 1 and i am getting P2, so it seems correct, but once I apply the ratio 1.11 things change.
I am trying to test colinearity by applying the cross product on vectors (P3-P1) and (P2-P1). It's a correct test right?

Would it be correct to verify colinearity by checking that the distance from P1 to P2 + distance P2 to P3 is equal to the distance from P1 to P1?

Could the different results be caused by a numerical instability?
 
Last edited:
  • #10
You can check collinearity of n vectors by throwing them in a matrix and doing row reduction.

But if you only compare two then you can either do dot or cross product (cross product is actually easier since with dot product you need to check that |<a,b>|/(||a||*||b||) = 1)
 
  • #11
I was trying to compute the area of the triangle formed by the points, thinking that if the area is 0 then the points are colinear, and I am getting the area either 0 or 0 real an dan imaginary part...is that normal?
why am i getting an imaginary part?
 
  • #12
catalin.drago said:
I was trying to compute the area of the triangle formed by the points, thinking that if the area is 0 then the points are colinear, and I am getting the area either 0 or 0 real an dan imaginary part...is that normal?
why am i getting an imaginary part?

My guess: roundoff like problems.
 

1. What is the purpose of finding a 3D point along a line at a given distance?

Finding a 3D point along a line at a given distance is useful in many fields, particularly in engineering, computer graphics, and physics. It allows us to accurately locate a specific point in space along a given line, which can be used for calculating distances, creating 3D models, or determining the position of objects in motion.

2. How is the distance measured for finding a 3D point along a line?

The distance is typically measured in the unit of length used in the 3D coordinate system, such as meters or feet. It can be calculated using mathematical formulas, such as the Pythagorean theorem or the distance formula, depending on the given information and the specific application.

3. What information is needed to find a 3D point along a line at a given distance?

To find a 3D point along a line at a given distance, we need to know the 3D coordinates of at least two points on the line and the distance from one of those points to the desired point. Additionally, we need to have a clear understanding of the coordinate system being used and the direction of the line.

4. What are some common methods for finding a 3D point along a line at a given distance?

Some common methods for finding a 3D point along a line at a given distance include using geometric formulas, vector operations, and parametric equations. These methods can be applied manually or using computer software, depending on the complexity of the problem and the available resources.

5. Are there any limitations to finding a 3D point along a line at a given distance?

While finding a 3D point along a line at a given distance is a useful tool, it does have some limitations. The accuracy of the result depends on the accuracy of the given information, and the calculations can become more complex for curved or intersecting lines. Additionally, finding a 3D point along a line at a given distance does not take into account any obstacles or variations in the environment that may affect the actual location of the point.

Similar threads

  • General Math
Replies
3
Views
881
Replies
2
Views
2K
  • Precalculus Mathematics Homework Help
Replies
17
Views
994
  • Engineering and Comp Sci Homework Help
Replies
1
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
14
Views
2K
  • Precalculus Mathematics Homework Help
Replies
7
Views
881
  • General Math
Replies
4
Views
2K
  • General Math
Replies
2
Views
2K
Replies
12
Views
2K
Replies
7
Views
7K
Back
Top