Revit API Forum
Welcome to Autodesk’s Revit API Forums. Share your knowledge, ask questions, and explore popular Revit API topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Distance between two points (XYZ) along a given vector

11 REPLIES 11
SOLVED
Reply
Message 1 of 12
mhillis
11233 Views, 11 Replies

Distance between two points (XYZ) along a given vector

Simple question, does the Revit API have a method of returning the distance between two points along a given vector?

 

I realize there are ways to manually do this, but I was wondering if the Revit API had something natively to make my code a little cleaner.

 

Thanks!

11 REPLIES 11
Message 2 of 12
GonçaloFeio1321
in reply to: mhillis

You can use a Autodesk.Revit.DB.Line

There is a double Length property that it inherits from Curve.

 

 

Message 3 of 12
matthew_taylor
in reply to: mhillis

Hi @mhillis

Where pointA and pointB are XYZ points:

dim distance as double = pointA.DistanceTo(pointB)

The XYZ class also has .multiply and .divide functions if you want to go a proportion of that distance along a vector.

 

 

Cheers,

 

-Matt


Cheers,

-Matt
_______________________________________________________________________________
Marking a post as a 'solution' helps the community. Giving a post 'Kudos' is as good as saying thanks. Why not do both?
Message 4 of 12

Shame on me, Mr. Taylor, shame on me for missing that! 

Message 5 of 12

Haha. I did a similar thing just yesterday, so don't feel bad! Smiley Very Happy


Cheers,

-Matt
_______________________________________________________________________________
Marking a post as a 'solution' helps the community. Giving a post 'Kudos' is as good as saying thanks. Why not do both?
Message 6 of 12
FAIR59
in reply to: mhillis

If you need the distance of the points projected onto the given vector:

 

XYZ p1 = new XYZ(0, 10, 0);

XYZ p2 = new XYZ(10, 60, 0);

XYZ direction = new XYZ(30, 60, 0);

double distance = direction.Normalize().DotProduct(p1.Subtract(p2));

// double distance = Math.Abs( direction.Normalize().DotProduct(p1.Subtract(p2)));

 

Message 7 of 12
jeremytammik
in reply to: mhillis

Dear Everybody,

 

I would award the main prize and cigar to Fair59.

 

Partly for providing what I guess might be the right answer.

 

Above all for guessing what may or may not be the right intended question.

 

Dear @mhillis, you might want to hone your question asking skills a bit.

 

Is this an accurate description of your needs?

point_dist_along_vector.png

 

 

Question: Given points p1 and p2, what is the distance between them, measured along the line L?

 

If that is indeed what you need, you are actually not asking about the distance between the points at all.

 

These two points, together with the direction w of L, define two planes.

 

You are asking about the distance between those two planes.

 

Are you?

 

If so, Fair's answer is absolutely accurate and can be reformulated as:

 

Answer:

 

  v = p2 - p1
  w = L.direction.normalise
  distance_along_w = v.dotProduct( w )

 

Unfortunately, the Revit geometry API is not full-fledged and therefore lacks a method to return the distance between two planes.

 

Otherwise, that would probably provide an even more straightforward path.

 

The suggested one is very direct and efficient, though, and hard to beat in those respects.

 

I hope this helps and that we collectively succeeded at nailing your intention.

 

Best regards,

 

Jeremy



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

Message 8 of 12
jeremytammik
in reply to: jeremytammik

I promoted this thread to a blog post for better legibility and future reference:

 

http://thebuildingcoder.typepad.com/blog/2017/01/distances-switches-kiss-ing-and-a-dino.html#2

 

Cheers,

 

Jeremy



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

Message 9 of 12
GOverfield
in reply to: mhillis

It seems to me that everyone went a little too hard on this.  If you need a distance between two points:

double rDist = fLocation1.DistanceTo(fLocation2);

where `fLocation1` and `fLocation2` are `XYZ` data types (Autodesk.Revit.DB namespace)

Message 10 of 12
jeremytammik
in reply to: GOverfield

Too hard or not... depends on whether you want the shortest distance between two points, or the distance along a given direction.

 

The latter is actually not the distance between two points, but the distance between two planes.

 

For safety's sake, I added this clarification to the existing blog post:

 

http://thebuildingcoder.typepad.com/blog/2017/01/distances-switches-kiss-ing-and-a-dino.html#2.1

 

Cheers,

 

Jeremy



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

Message 11 of 12
mhillis
in reply to: jeremytammik


@Anonymous wrote:

Too hard or not... depends on whether you want the shortest distance between two points, or the distance along a given direction.

 

The latter is actually not the distance between two points, but the distance between two planes.

 

For safety's sake, I added this clarification to the existing blog post:

 

http://thebuildingcoder.typepad.com/blog/2017/01/distances-switches-kiss-ing-and-a-dino.html#2.1

 

Cheers,

 

Jeremy


Jeremy,

 

I am surprised to see this particular forum post has so much activity.   For further clarification for those who may travel here in the future, and upon retrospect, yes, you're absolutely correct in your initial assumption when I first posed this question.  I was looking for the distance between two planes, my initial question was a very round-a-bout way of getting to that point, but I am glad we were able to get there either way.

 

I didn't make a comment, but I did mark you and FAIR's response as an answer because they gave me exactly what I was looking for.  Putting together a small routine utilizing the information I was given gave me A) a nice, recallable routine, B) something that I can tailor to my needs.

 

As an aside, I realize that measuring between planes isn't something 'native' to Revit as you described, but being sort of pigeon-holed into making your own routines has the benefit of allowing me to make methods for simple functions that I can expand/modify as needed.

 

If it is, in some way, possible to edit my initial post for clarification to those in the future, that would be nice. 

Message 12 of 12
jeremytammik
in reply to: mhillis

Dear Mhillis,

 

Thank you very much for your confirmation and appreciation.

 

I am glad we were able to help and contribute to a clean, reliable and reusable solution.

 

I am not aware of a possibility to edit your original post, and I can imagine some reasons why that should be avoided...

 

That is one reason why I like summarising discussions like these on The Building Coder 🙂

 

... So, I added your new comment to the discussion there as well...

 

Cheers,

Jeremy



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Rail Community