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: 

Find perpendicular point from one point to a line

7 REPLIES 7
SOLVED
Reply
Message 1 of 8
Anonymous
3901 Views, 7 Replies

Find perpendicular point from one point to a line

Hi everyone, 

 

I just start with point in Revit API and quite confuse of how to find a perpendicular point (H point) from a known point A to line CB (have 2 points C & B that already have XYZ information) : 

Question 1.png

 

Thank you so much for your great help.

 

Best Regards,

 

Cherry Truong

7 REPLIES 7
Message 2 of 8
BenoitE&A
in reply to: Anonymous

Hey,

Use:

 

Line lineBC;

XYZ pointA;

XYZ pointH = lineBC.Project(pointA).XYZPoint;

 

Bye

Benoit


Benoit FAVRE
CEO of etudes & automates
www.etudesetautomates.com/
Tags (2)
Message 3 of 8
Anonymous
in reply to: BenoitE&A

Thank you so much for your great simple solution Smiley Very Happy.

Message 4 of 8
jlpgy
in reply to: Anonymous

Hi @Anonymous:

Notice if your are dealing with the following situation:

图像 1.png

Your codes should be little bit more complicated then.

// Suppose you have already got these points
XYZ pointA, pointB, pointC;
Line unboundLine = Line.CreateBound(pointB, pointC);
unboundLine.MakeUnbound();

XYZ pointH = unboundLine.Project(pointA).XYZPoint;

There is another method: Line.CreateUnbound(XYZ, XYZ), which is easier for creating unbound line. Remember to immediately dispose the Line if you are sensitive with performance.

 

 

In my projects, we have wrapped them into several methods:

        public static XYZ UnboundProject(this Line line, XYZ point)
        {
            using (Line unboundLine = line.GetUnbound())
            {
                IntersectionResult result = unboundLine.Project(point);
                Debug.Assert(result != null);

                return result.XYZPoint;
            }
        }
        public static Line GetUnbound(this Line line)
        {
            if (line.IsBound)
            {
                Line cloned = line.Clone() as Line;
                cloned.MakeUnbound();
                return cloned;
            }
            else
            {
                return line.Clone() as Line;
            }
        }

 

 

单身狗;代码狗;健身狗;jolinpiggy@hotmail.com
Message 5 of 8
Anonymous
in reply to: jlpgy

Hi @jlpgy,

 

Thank you so much for the great solution. I just implemented your suggestion into my code and it worked great. 

Million likes Smiley Very Happy

 

Best Regards,

 

Cherry Truong

Message 6 of 8
Anonymous
in reply to: jlpgy

Hi @jlpgy,

 

Regarding to your last answer of the perpendicular point, I faced another problem as following image: 

1.PNG

Suppose I already have 3 point (A, B , C) are know point (with XYZ information). So if I want to create a line CD that has angle to AB with value X (radian or degree), how should I do that? 

Thank you so much for your help :).

 

Best Regards,

 

Cherry Truong

Message 7 of 8
BenoitE&A
in reply to: Anonymous

Hey,

It looks like you have some Maths for me. All you have to do is find the intersection, right?

Here it goes :

 

XYZ A, B, C;

double x;

// Determine a vector making angle x to AB

// Get direction of AB (normalized)

XYZ base1 = Line.CreateBound(A, B).Direction;

// Get direction perpendicular to base1 (normalized)

XYZ base2 = -base1.CrossProduct(XYZ.BasisZ);

 

// Get the direction of your line CD

XYZ directionCD = Math.Cos(x) * base1 + Math.Sin(x) * base2;

 

This way is similar to changing the coordinates to the base attached to AB and computing the transformation of a point in a rotation of angle x.

You can compute D with :

Line CD = Line.CreateUnbound(C, direction CD);

SetComparisonResult scr = courbe.Intersect(dicoLocMur[i], out IntersectionResultArray ira);
if (scr == SetComparisonResult.Overlap)
{

XYZ D = ira.get_Item(0).XYZPoint;

}

Have fun !

Benoit


Benoit FAVRE
CEO of etudes & automates
www.etudesetautomates.com/
Message 8 of 8
Anonymous
in reply to: BenoitE&A

Hi @BenoitE&A,

 

Once again thank you so much for the great suggestion. This remind me of high school math Smiley Very Happy.

Have a great day.

 

Best Regards,

 

Cherry Truong

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

Post to forums  

Autodesk Customer Advisory Groups


Rail Community