Hi,
I’m looking for the .net equivalent of RhinoScript’s function Angle(point1, point2, plane)
but I can’t find it.
Any idea?
Regards
there is a rhinocommon method that you could use:
https://developer.rhino3d.com/api/RhinoCommon/html/Overload_Rhino_Geometry_Vector3d_VectorAngle.htm
maybe something like this?
v1 = Rhino.Geometry.Vector3d(pt1 - pl.Origin)
v2 = Rhino.Geometry.Vector3d(pt2 - pl.Origin)
a = Rhino.Geometry.Vector3d.VectorAngle(v1, v2)
Thanks @chanley, I’ll try this when I have the time, although I’m not sure if the result would be the same.
By the way, since origin is zero, I think we can directly cast the points as vectors:
a = Rhino.Geometry.Vector3d.VectorAngle(new vector(Pt1),new vector(Pt2))
I’ll give you a feedback later
ah, i think you are correct. My answer is not what you are looking for! I didn’t fully read what that function actually returned.
For what it’s worth, this is is the rhinocommon/python code behind the rs function you initially posted about.
(it’s taken from the utility.py file, which is located on your computer here: (version may vary)
%USERPROFILE%\AppData\Roaming\McNeel\Rhinoceros\6.0\Plug-ins\IronPython (814d908a-e25c-493d-97e9-ee3861957f49)\settings\lib\rhinoscript)
def Angle(point1, point2, plane=True):
"""Measures the angle between two points
Parameters:
point1, point2 (point): the input points
plane (bool, optional): Boolean or Plane
If True, angle calculation is based on the world coordinate system.
If False, angle calculation is based on the active construction plane
If a plane is provided, angle calculation is with respect to this plane
Returns:
tuple(tuple(number, number), number, number, number, number): containing the following elements if successful
element 0 = the X,Y angle in degrees
element 1 = the elevation
element 2 = delta in the X direction
element 3 = delta in the Y direction
element 4 = delta in the Z direction
None: if not successful
Example:
import rhinoscriptsyntax as rs
point1 = rs.GetPoint("First point")
if point1:
point2 = rs.GetPoint("Second point")
if point2:
angle = rs.Angle(point1, point2)
if angle: print "Angle: ", angle[0]
See Also:
Angle2
Distance
"""
pt1 = coerce3dpoint(point1)
if pt1 is None:
pt1 = coercerhinoobject(point1)
if isinstance(pt1, Rhino.DocObjects.PointObject): pt1 = pt1.Geometry.Location
else: pt1=None
pt2 = coerce3dpoint(point2)
if pt2 is None:
pt2 = coercerhinoobject(point2)
if isinstance(pt2, Rhino.DocObjects.PointObject): pt2 = pt2.Geometry.Location
else: pt2=None
point1 = pt1
point2 = pt2
if point1 is None or point2 is None: return scriptcontext.errorhandler()
vector = point2 - point1
x = vector.X
y = vector.Y
z = vector.Z
if plane!=True:
plane = coerceplane(plane)
if plane is None:
plane = scriptcontext.doc.Views.ActiveView.ActiveViewport.ConstructionPlane()
vfrom = point1 - plane.Origin
vto = point2 - plane.Origin
x = vto * plane.XAxis - vfrom * plane.XAxis
y = vto * plane.YAxis - vfrom * plane.YAxis
z = vto * plane.ZAxis - vfrom * plane.ZAxis
h = math.sqrt( x * x + y * y)
angle_xy = math.degrees( math.atan2( y, x ) )
elevation = math.degrees( math.atan2( z, h ) )
return angle_xy, elevation, x, y, z