Search Unity

## Calculate the extension of a line

Discussion in 'General Graphics' started by Quatum1000, Feb 15, 2018.

  1. Quatum1000

    Quatum1000

    Joined:
    Oct 5, 2014
    Posts:
    889
    Hi everyone,

    I like to calculate the extension of line in 3D. Lets say we have p1(x,y,z) and p2(x,y,z).
    The distance between p1 and p2 is eg. 10m.

    Untitled-1.jpg

    Now I want to get the 3D points of C,D,E by a function:
    The extension direction should go to the second argument in this case p2
    verctor3 = GetLineExtenstionPoint(newDistance, p1, p2)
    For sure minus newDistance should give the point between p1 and p2.

    And the extension direction should direct to p1 in this case.
    verctor3 = GetLineExtenstionPoint(newDistance, p2, p1)

    Does anyone know how to?
    Thanks a lot!
     
    Last edited: Feb 15, 2018
  2. brownboot67

    brownboot67

    Joined:
    Jan 5, 2013
    Posts:
    375
    Lerp between them based on the ratio of the current distance and the desired distance... Take the normalized vector and move along it... Few ways to skin that cat.
     
  3. Quatum1000

    Quatum1000

    Joined:
    Oct 5, 2014
    Posts:
    889
    something like this?
    var n = vector3.Distance(p1,p2);
    var newpos = Vector3.Lerp(p1, p2, n * newDistance);

    hmm... I think n must be normalized
     
    Last edited: Feb 15, 2018