Hello,I define a vextor via two points(ptStart and ptDirection).And now I want to get the angle between my vector3d and the X Axis.Here is my code:
Dim Ang As Double = ptStart.GetVectorTo(ptDirection).GetAngleTo(Vector3d.XAxis)
But the range is 0-PI.How can I change it to 0-2PI?
Hi,
I see there is another version of this method:
Returns the angle between this vector and the vector vector in the range [0, 2 x Pi].
Please, find its description in the Managed Class Reference Guide (\ObjectARX 2012\docs\arxmgd.chm).
Hi! Try this.
double Ang = ptStart.GetVectorTo(ptDirection).GetAngleTo(Vector3d.XAxis, Vector3d.ZAxis.Negate());
hi marat
although i do not want to spoil the party, i desperately fail to obtain any angles above the 0-pi interval. i admit i still use autocad 2011, however, the documentation for the .getangleto(vec; vecref) appears as you state.
considering the problem, i could do myself with some clarification as to how it's supposed to work:
starting with a vector3d, i look for the angle to another vector3d. to keep things simple, let's say they both originate in the same point and 'point away' from it in separate directions. why is there an optional reference-vector3d? if it's only to expand the interval from 0-pi to 0-2*pi, then an optional boolean would have been satisfactory.
many thanks, felix
yes of course, as soon as i posted it...
to whom it may concern
the additional vecref can be used to define [or fixate] that one dimension of the three (in 3d) that leaves the other two to span the plane in which the angle is measured. in turn it means that the option without the vecref leaves it completely to the two original vectors, i.e. the calling one and the parameter one, to define a plane and the angle within, which also explains why then with the information given it is not possible to give angles above pi, because 'they technically then do not exist'.
hope you enjoyed the show
felix
hello. Sorry for ressurecting a thread, but I have an issue using the "getAngle".
the problem is the angle I'm getting is nowhere in the PI range
all the "input numbers" turn out as expected.
here's my code:
using (Transaction tr = db.TransactionManager.StartTransaction()) { ObjectId id = res.ObjectId; Point3d picked = res.PickedPoint; var pline = tr.GetObject(id, OpenMode.ForRead) as Polyline; Point3d onPlinePt = pline.GetClosestPointTo(picked, ed.GetCurrentView().ViewDirection, false); Line3d perpLine = new Line3d(picked, onPlinePt); Vector3d xAxis = new Vector3d(1,0,0); Vector3d perpVector = onPlinePt-picked; double myAngleRad = perpVector.GetAngleTo(Vector3d.XAxis, Vector3d.ZAxis.Negate()); double myAngle = myAngleRad * 180 / Math.PI; }
and here's the result:
any ideas what I'm doing wrong?
Hi,
The angle you get is in the 0 2pi range.
1.0094597E-188 (scientific notation) is just very closed to 0.0.
true, it was por choice of expression.
my question stands, since I've been getting numbers 10e-188 no matter if I chose vertical, horizontal, or @ 45 deg objects
4 example, this is the result for a completely horizontalline - vector (1,0,0).
the angle to Y axis should be 90deg or PI/2 (1,57)
instead, I get this results...
5thSth a écrit :
4 example, this is the result for a completely horizontalline - vector (1,0,0).
the angle to Y axis should be 90deg or PI/2 (1,57)
No, internally (and programmatically) AutoCAD always measures angles in radians, CCW and starting from East.
If you have different settings (e.g. ANGDIR / ANGBASE), you have to make some calculus to convert the angle or use the Converter.AngleToString() method.
try:
AngleToString(perpVector.GetAngleTo(Vector3d.XAxis, Vector3d.ZAxis));
Ive tried it, but "angleToString" method:
var newAngle = Autodesk.AutoCAD.Runtime.Converter.AngleToString(Vector3d.XAxis.GetAngleTo(Vector3d.YAxis,Vector3d.ZAxis)); Application.ShowAlertDialog("Angle between X and Y axis is:" + newAngle);
and result angle for X and Y axis turns out to be "0" 😞
and if I try only to .GetAngleTo(Vector3d.Yaxis) without Z ... : 314 (which is more of a "Rad" result.
-will keep experimenting; ty
but I'd still like to know what the problem was with other method ;
its not a "rad/angle" conversion problem. I know all about rads, and the results Im getting are nowhere near to expected rad or deg results.
to make the problem more apparent, I've rewritten the code to print the
angle to X and Y axis... which is "90 deg" or "PI/2" in rads which is equal to "1,57"
angle to X and X axis... which is "0,00 deg" or "0,00" in rads which equals to "0,00"
double angleResult = new double(); double angleResult2 = new double(); angleResult = Vector3d.XAxis.GetAngleTo(Vector3d.YAxis); angleResult2 = Vector3d.XAxis.GetAngleTo(Vector3d.XAxis); Application.ShowAlertDialog("axisX vector:" + Vector3d.XAxis.ToString() + "\naxisY vector:" + Vector3d.YAxis.ToString() + "\nAngle axisX to axisY: " + angleResult.ToString()+ "\nAngle axisX to axisX" + angleResult2.ToString());
you can tell something is really wrong simply by looking at it... since angle1 and angle2 results turn out to be the same number!!! (-2,4785E +215)
wow!
Thank you for going through the trouble of testing it.
😞
will try to run code on desktop.
could be AMD cpu...
on my desktop I get correct result.
but I tried to find where the bug is on laptop...
and when I run the dll directly from autocad, it gives correct result.
however, if I try to "debug" through visual studio, I get the above mentioned "error" results
It appears the problem was my windows. I was using windows 10 -Technical Preview
I upgraded to win 10, and the problem is gone (same visual studio and Acad and it works)