Revit API Forum
Welcome to Autodesk’s Revit API Forums. Share your knowledge, ask questions, and explore popular Revit API topics.

Revit API Forum

Reply
Highlighted
Post 1 of 8
Accepted Solution

Distance between two points (XYZ) along a given vector

190 Views, 7 Replies
12-13-2016 04:06 PM

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!

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)));

 

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

Re: Distance between two points (XYZ) along a given vector

12-13-2016 04:44 PM in reply to: mhillis

You can use a Autodesk.Revit.DB.Line

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

 

 

Post 3 of 8

Re: Distance between two points (XYZ) along a given vector

12-14-2016 01:36 AM 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?

Re: Distance between two points (XYZ) along a given vector

12-14-2016 02:55 AM in reply to: matthew.taylor

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

Post 5 of 8

Re: Distance between two points (XYZ) along a given vector

12-14-2016 03:30 AM in reply to: GonçaloFeio1321

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?
Post 6 of 8

Re: Distance between two points (XYZ) along a given vector

12-14-2016 04:17 AM 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)));

 

Post 7 of 8

Re: Distance between two points (XYZ) along a given vector

12-14-2016 10:36 AM 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

Post 8 of 8

Re: Distance between two points (XYZ) along a given vector

01-09-2017 04:26 AM 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

Post to the Community

Have questions about Autodesk products? Ask the community.

New Post

Revit Exchange Apps

Created by the community for the community, Autodesk Exchange Apps for Revit helps you achieve greater speed, accuracy, and automation from concept to manufacturing.