Get Angle between two points

Get Angle between two points

MarkSanchezSPEC
Advocate Advocate
6,977 Views
2 Replies
Message 1 of 3

Get Angle between two points

MarkSanchezSPEC
Advocate
Advocate

With the Plant 3D or AutoCAD .NET API, I can "calculate a vector between two points and determines the angle from the X-axis" like this:

 

Plant 3D
--------------------
Dim pt1 As New Point2d(2142.371247, -2066.73581)
Dim pt2 As New Point2d(2142.371247, -1989.581039)
Dim angle As Double = pt1.GetVectorTo(pt2).Angle	'RETURNS 1.5707963267948966 IN RADIANS, WHICH IS 90-DEGREES

I'm not able to do likewise with the Revit API however. I've tried the "AngleOnPlaneTo" and "AngleTo" but do not get the expected results as above:

 

Dim pt1 As New XYZ(2142.371247, -2066.73581)
Dim pt2 As New XYZ(2142.371247, -1989.581039)
Dim angle2 As Double = pt1.AngleOnPlaneTo(pt2, New XYZ(0, 0, 1))	'RETURNS 0.01899334843737778
Dim angle3 As Double = pt1.AngleTo(pt2)	'RETURNS 0.018159197737853211

 

 Any suggestions?

0 Likes
Accepted solutions (1)
6,978 Views
2 Replies
Replies (2)
Message 2 of 3

jeremytammik
Autodesk
Autodesk
Accepted solution

Dear Mark,

 

Thank you for your query.

 

The AngleTo method documentation says that it "returns the angle between this vector and the specified vector":

 

http://www.revitapidocs.com/2017/4251dd2b-1b48-8b2e-7159-02333cdf39e6.htm

 

The input you define above is given as points.

 

You need to convert your point input to vectors, e.g.:

 

  XYZ pt1 = New XYZ(2142.371247, -2066.73581, 0)
  XYZ pt2 = New XYZ(2142.371247, -1989.581039, 0)
  XYZ vector_from_pt1_to_pt2 = pts - pt1
  double angle = vector_from_pt1_to_pt2.AngleTo( XYZ.BasisX )

By the way, if you are just starting to explore the Revit API, I would strongly suggest working through the getting started material first:

 

http://thebuildingcoder.typepad.com/blog/about-the-author.html#2

 

I hope this helps.

 

Best regards,

 

Jeremy



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

Message 3 of 3

MarkSanchezSPEC
Advocate
Advocate

Thank you sir.

0 Likes