Calculate new point with vector and distance

Calculate new point with vector and distance

amati_p
Participant Participant
587 Views
3 Replies
Message 1 of 4

Calculate new point with vector and distance

amati_p
Participant
Participant

Hey there,

 

I want to calculate the position of a new point with my point, a vector and a distance. How to do that?

 

Cordially.

0 Likes
Accepted solutions (1)
588 Views
3 Replies
Replies (3)
Message 2 of 4

Mohamed_Arshad
Advisor
Advisor

HI @amati_p 

you have to subtract newpoint from mypoint to get vector.

 

Kindly refer to the below code:

 

            XYZ mypoint = new XYZ(0, 0, 0);
            XYZ newPoint = new XYZ(20, 5, 7);

            //To Get Vector you have subtract newpoint from mypoint
            XYZ vector = newPoint.Subtract(mypoint);

            //To Get Distance it is Feet by default you have to convert the units.
            double magnitude = vector.GetLength();

 

Hope this Helps 🙂


Mohamed Arshad K
Software Developer (CAD & BIM)

0 Likes
Message 3 of 4

michael-coffey
Advocate
Advocate
Accepted solution

@Mohamed_Arshad It sounds like they are looking to make a new point, not get a distance.

 

@amati_p Create a vector using -1, 1 and 0 values.  Multiple the vector by the distance (in this case 5) then add to the first point.

XYZ firstPoint = new XYZ(0,0,0);
XYZ vector = new XYZ(1,1,0);
XYZ newPoint = firstPoint + (vector * 5);

 This will yield a new point at 5,5,0.

Message 4 of 4

jeremy_tammik
Alumni
Alumni

Thanks to @michael-coffey  for the helpful answer. That code assumes that the given vector is already normalised, i.e., has length 1.0. It is also defined in the 2D space defined by the horizontal XY plane. In more generic terms, given a point P, a vector V and a distance D, to can calculate the desired target point Q like this:

  

  Q = P + D * V.Normalize()

  

I would very much recommend playing around a bit in some vector algebra tutorial space to get a hang of the basics before trying to implement any calculations in a complex real-world BIM, e.g., 

  

  

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
0 Likes