turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Close

Revit API Forum

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

- Autodesk Community
- >
- Revit
- >
- API Forum
- >
- Distance between two points (XYZ) along a given vector

Revit: Revit API Forum: (Accepted Solution) Distance between two points (XYZ) along a given vector: Page 1

Topic Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic to the Top
- Bookmark
- Subscribe
- Printer Friendly Page

Highlighted
# Distance between two points (XYZ) along a given vector

Options

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report

141 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!

Solved! Go to Solution.

Solved! by FAIR59. See the answer in context.

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

Solved! by jeremytammik. See the answer in context.

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?

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

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report

You can use a Autodesk.Revit.DB.Line

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

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report

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

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report

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

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report

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

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report

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

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report

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?

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

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report

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

http://thebuildingcoder.typepad.com/blog/2017/01/d

Cheers,

Jeremy

Search This Board

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Post to the Community

Have questions about Autodesk products? Ask the community.

Related Content

Search the Autodesk Knowledge Network for more content.

Download & Installation

Windows 10 Support

Autodesk Online Store Help

Software Downloads

Serial Numbers & Product Keys

Installation & Licensing

Online Activation & Registration

Manual Software Activation

Network License Administration

Subscription Management

Sign In / Create Account

Maintenance Subscription Help

Desktop Subscription Help

Cloud Service Subscription FAQ

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

*Autodesk is a leader in 3D design, engineering and entertainment software.*

- Privacy/Cookies (Updated) | Legal Notices & Trademarks | Report Noncompliance | Site map | © 2016 Autodesk Inc. All rights reserved