Distance between two 3d Points

Distance between two 3d Points

Anonymous
Not applicable
5,169 Views
19 Replies
Message 1 of 20

Distance between two 3d Points

Anonymous
Not applicable

Hello!

I need to find the distance between two different points in 3D view.

And these points placed in different planes.

Are there any solutions for my problem?

0 Likes
Accepted solutions (1)
5,170 Views
19 Replies
Replies (19)
Message 2 of 20

Anonymous
Not applicable
0 Likes
Message 3 of 20

RPTHOMAS108
Mentor
Mentor

When you use PickObject you'll get a reference with a global point property.

 

With .PickPoint you'll have to change the active workplane between point selections.

 

Then either use Revit XYZ class:

 

XYZ.DistanceTo(XYZ)

 

or Pythagoras (not the guy the theorem by the guy).

0 Likes
Message 4 of 20

Anonymous
Not applicable
So, it’s better to use PickObject?
And if I am going to find distance along the vector, what vector it should be? How can I identify vector I need?
0 Likes
Message 5 of 20

RPTHOMAS108
Mentor
Mentor

The vector would be your choice according to what you want it for i.e. a projection on a surface.

 

If you just want the minimum distance between points then XYZ.DistanceTo will give you that and it doesn't need a vector.

 

PickPoint vs PickObject is your choice. Picking an object is not as exact as picking a point (since you are picking somewhere on a curve or face and not a specific point) but perhaps that could be remedied with object snap settings (unsure).

0 Likes
Message 6 of 20

Anonymous
Not applicable
DistanceTo is not ok for me. It seems like I need to find distance between two planes, cause I want to select points in 3d view. And as far as I understand, distanceTo doesn’t make a reliable measurement in 3d
0 Likes
Message 7 of 20

RPTHOMAS108
Mentor
Mentor

That's a bad understanding of DistanceTo function since all it is doing is working out distance between two points (probably as below):

 

3D_Distance = Sqrt((X1 - X2)^2 + (Y1 - Y2)^2 + (Z1 - Z2)^2)

 

If you want the projected distance onto a plane then that is a different problem but all you've said so far is that you want the distance between two 3D points.

 

 

 

 

0 Likes
Message 8 of 20

Anonymous
Not applicable
Yes, I just need to select two points in 3d view and find the distance between. But when I use DistanceTo and PickPoint, the measure is depend on the view. And when I rotate my model and choose these points again, the distance will be different
0 Likes
Message 9 of 20

RPTHOMAS108
Mentor
Mentor
Accepted solution

Is this because you are picking on a flat plane both points and need to switch the plane between each pick?

 

You'll never get the Z co-ordinate you need that way and if you could you would just replace the Z coordinate of the points to the Z values of the levels they were actually picked at.

 

Regardless of the calculation the form of picking would be confusing to the user since the object snap icons etc. would be occurring under other 3D objects (you need to switch the plane for each pick).

 

I believe your problem is you aren't actually picking the same two points, from a different angle other items get in the way and are picked first.

0 Likes
Message 10 of 20

Anonymous
Not applicable
So, if I will choose the plane for every picked point, I can use DistanceTo, and everything will be ok?
0 Likes
Message 11 of 20

RPTHOMAS108
Mentor
Mentor

Yes, I had an addin which did exactly this. Main problem is it is a bit clunky asking the user to pick a plane each time.

 

You should also investigate PickObject in conjunction with object snaps. However in a lot of cases in 3D it is hard to ensure the thing you are picking is the thing in the foreground you expect to be picking (hence why they ask you to set a plane in PickPoint).

0 Likes
Message 12 of 20

Anonymous
Not applicable
Thank you so much! I will try it
0 Likes
Message 13 of 20

FAIR59
Advisor
Advisor

from your description I presume you want to get points on a face or edge of a "real / modelled" Element.

In that case you'd be better off using the Selection.PickObject() method and use the globalPoint of the returned Reference.

 

			Selection sel = uidoc.Selection;
			Reference res = null;
			try{
				res = sel.PickObject(ObjectType.PointOnElement ,new MySelectionFilter(),"pick a point on an element");
			}
catch{} XYZ point = res.GlobalPoint;

These points are not dependent on the workplane, so the distance is point1.DistanceTo(point2);

 

The method uses a SelectionFilter, so you can narrow the picked point to certain Elements.

 

A SelectionFilter that accepts all Elements is:

 public class MySelectionFilter : ISelectionFilter
    {
        public bool AllowElement(Element elem)
        {
            return true;
        }
        public bool AllowReference(Reference refer, XYZ pos)
        {
        	return true;
        }
    }

  

 

0 Likes
Message 14 of 20

Anonymous
Not applicable
I also need to select points from Point Cloud in linked file. This why I use PickPoint in my code. And I don’t know, how PickObject works with Point Cloud
0 Likes
Message 15 of 20

FAIR59
Advisor
Advisor

to pick element from linked file use 

 

sel.PickObject(ObjectType.LinkedElement,new AllSelectionFilter(),"pick something");

You'd have to test if you can pick PointCloud points

0 Likes
Message 16 of 20

Anonymous
Not applicable
Ok, thank you !
0 Likes
Message 17 of 20

Anonymous
Not applicable
I tried to calculate the distance from DistanceTo and selecting plane each time. But the result is wrong
I know that distance should be 4000, but when I do my code, distance is just 7
And I can’t understand how the coordinates of selected points calculated? Is it projection on the plane?
0 Likes
Message 18 of 20

Anonymous
Not applicable

This will not help in your problem (I think), but just make sure the units that are sown in the UI are as you expect them to be:

 

distance = UnitUtils.ConvertFromInternalUnits(distance, DisplayUnitType.DUT_METERS); //make sure it is m

Cheers

Ruben

Message 19 of 20

Anonymous
Not applicable

Yea! It was very helpful! I just did and it works!

distance *= 1000;
0 Likes
Message 20 of 20

Anonymous
Not applicable

Those are great news! Sometimes simple things can give us a lot of trouble

 

Cheers