.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Angle From XAxis

12 REPLIES 12
Reply
Message 1 of 13
Anonymous
969 Views, 12 Replies

Angle From XAxis

Hi dose anyone know the .net version of AngleFromXAxis(StartPoint, EndPoint) in VB 6
12 REPLIES 12
Message 2 of 13
Anonymous
in reply to: Anonymous

public double AngleFromXAxis( Point3d point )
{
return new Vector2d( point.X, point.Y ).Angle;
}

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2008
Supporting AutoCAD 2000 through 2008
http://www.acadxtabs.com

wrote in message news:5585245@discussion.autodesk.com...
Hi dose anyone know the .net version of AngleFromXAxis(StartPoint, EndPoint) in VB 6
Message 3 of 13
Anonymous
in reply to: Anonymous

Thanks.
Message 4 of 13
Anonymous
in reply to: Anonymous

public Point3d PolarPoint(Point3d basepoint, double angle, double distance)
{
return new Point3d(
basepoint.X + (distance * Math.Cos(angle)),
basepoint.Y + (distance * Math.Sin(angle)),
basepoint.Z);
}




--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2008
Supporting AutoCAD 2000 through 2008
http://www.acadxtabs.com

wrote in message news:5585637@discussion.autodesk.com...
Thanks.
Message 5 of 13
Anonymous
in reply to: Anonymous

See how it will works for you

~'J'~

_
Sub TestAngle()
Dim adoc As Document = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument
Dim ed As Editor = adoc.Editor
Dim p1 As Point3d = New Point3d(0, 0, 0)
Dim p2 As Point3d = New Point3d(1000, 1111, 0)
ed.WriteMessage(vbNewLine & "Angle from #1 x axis = " & (AngleFromX(p1, p2, ed) * 180 / Math.PI).ToString & " degrees")
p1 = New Point3d(0, 0, 0)
p2 = New Point3d(-1000, -1111, 0)
ed.WriteMessage(vbNewLine & "Angle #2 from x axis = " & (AngleFromX(p1, p2, ed) * 180 / Math.PI).ToString & " degrees")

End Sub

Public Shared Function AngleFromX(ByVal pt1 As Point3d, ByVal pt2 As Point3d, ByVal ed As Editor) As Double
Dim ucsmtx As Matrix3d = ed.CurrentUserCoordinateSystem
Dim ucs As CoordinateSystem3d = ucsmtx.CoordinateSystem3d
Dim ucsplane As Plane = New Plane(ucs.Origin, ucs.Xaxis, ucs.Yaxis)
Dim vec As Vector3d = pt2 - pt1
Dim ang As Double = vec.AngleOnPlane(ucsplane)
Return ang
End Function
Message 6 of 13
cadMeUp
in reply to: Anonymous

Am I calling this correctly?:

double degAng = 270.00;
double radAng = (Math.PI * (degAng / 180.00));
Point3d pnt = PolarPoint(new Point3d(0, 0, 0), radAng, 5.0);
editor.WriteMessage("\n" + pnt);

This is the result I get:
(-9.18454765366783E-16,-5,0)

Should be?:
(0,-5,0)
Message 7 of 13
jbooth
in reply to: Anonymous

You have round-off error, where the computer's accuracy wasn't enough to calculate an exact result.

-9.18454765366783E-16 is very close to zero, and is only non-zero because of the error associated with floating point numbers.

ie: your result was:
(-0.0000000000000000918454765366783,-5,0)

You have to admit, that's pretty damn close to (0,-5,0). 😉
Message 8 of 13
Anonymous
in reply to: Anonymous

Seems pretty close to me.

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2008
Supporting AutoCAD 2000 through 2008
http://www.acadxtabs.com

wrote in message news:5764413@discussion.autodesk.com...
Am I calling this correctly?:

double degAng = 270.00;
double radAng = (Math.PI * (degAng / 180.00));
Point3d pnt = PolarPoint(new Point3d(0, 0, 0), radAng, 5.0);
editor.WriteMessage("\n" + pnt);

This is the result I get:
(-9.18454765366783E-16,-5,0)

Should be?:
(0,-5,0)
Message 9 of 13
Anonymous
in reply to: Anonymous

I know its been a while but I wondered if this bit of code (specifically your AngleFromX function) was an equivalent to the lisp angle command?

If this isn't, is there any method that takes 2 points and returns an angle like "angle" in lisp?
Message 10 of 13
Anonymous
in reply to: Anonymous

{code}

If you mean the version I posted, yes, it should be functionally equivalent to the lisp (angle) function.

I think the docs for that function are confusing because it refers to the 'current ucs', which is not the case. The (angle) function presumes its arguments are WCS coordinates and the returned angle is the angle in WCS XY plane.

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2009
Supporting AutoCAD 2000 through 2009

http://www.acadxtabs.com

Introducing AcadXTabs 2010:
http://www.caddzone.com/acadxtabs/AcadXTabs2010.htm

wrote in message news:6046864@discussion.autodesk.com...
I know its been a while but I wondered if this bit of code (specifically your AngleFromX function) was an equivalent to the lisp angle command? If this isn't, is there any method that takes 2 points and returns an angle like "angle" in lisp?

{code}
Message 11 of 13
Anonymous
in reply to: Anonymous

Actually I was referring to the code in Fatty's post. It takes 2 points like angle from lisp does.

Public Shared Function AngleFromX(ByVal pt1 As Point3d, ByVal pt2 As Point3d, ByVal ed As Editor) As Double
Dim ucsmtx As Matrix3d = ed.CurrentUserCoordinateSystem
Dim ucs As CoordinateSystem3d = ucsmtx.CoordinateSystem3d
Dim ucsplane As Plane = New Plane(ucs.Origin, ucs.Xaxis, ucs.Yaxis)
Dim vec As Vector3d = pt2 - pt1
Dim ang As Double = vec.AngleOnPlane(ucsplane)
Return ang
End Function

Would this not be more similar?

I'm new to autocad and don't know much about the ucs and wcs. I haven't yet used this function "AngleFromX" in my program to verify the results.
Message 12 of 13
Anonymous
in reply to: Anonymous

The code I just posted takes two points as well.

The code in the older post is wrong, and only takes one point.

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2009
Supporting AutoCAD 2000 through 2009

http://www.acadxtabs.com

Introducing AcadXTabs 2010:
http://www.caddzone.com/acadxtabs/AcadXTabs2010.htm

wrote in message news:6046916@discussion.autodesk.com...
Actually I was referring to the code in Fatty's post. It takes 2 points like angle from lisp does.

Public Shared Function AngleFromX(ByVal pt1 As Point3d, ByVal pt2 As Point3d, ByVal ed As Editor) As Double
Dim ucsmtx As Matrix3d = ed.CurrentUserCoordinateSystem
Dim ucs As CoordinateSystem3d = ucsmtx.CoordinateSystem3d
Dim ucsplane As Plane = New Plane(ucs.Origin, ucs.Xaxis, ucs.Yaxis)
Dim vec As Vector3d = pt2 - pt1
Dim ang As Double = vec.AngleOnPlane(ucsplane)
Return ang
End Function

Would this not be more similar?

I'm new to autocad and don't know much about the ucs and wcs. I haven't yet used this function "AngleFromX" in my program to verify the results.
Message 13 of 13
Anonymous
in reply to: Anonymous

I don't know who all is responsible for that code in my previous post, but thanks. It works perfectly in returning exactly what "angle" in lisp gives me.

Now I only need to understand vectors and how it works better. Seems like its using two radians to get the angle.

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

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost