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

Vector3d.GetAngleTo method

3 REPLIES 3
Reply
Message 1 of 4
rui_pestana2
4513 Views, 3 Replies

Vector3d.GetAngleTo method

Hi,

the method "Vector3d.GetAngleTo";, retrieves always the minor angle between the two vectors?
For example in the code:

Dim acVector1 As Vector3d = New Vector3d(1,0,0)

Dim acVector2 As Vector3d = New Vector3d(-1,-1,0)

Dim rdAngle as double = acVector2.GetAngleTo(acVector1)

Dim dgAngle as double = rdAngle * 180 / Math.PI

the dgAngle results in 135 degrees (the minor angle between the vectors)

Is any way to retrieve the angle measured in anti-clockwise direction (like in AutoCAD) without further analyses to vectors ?

Thanks in advance.

Rui Pestana
3 REPLIES 3
Message 2 of 4
_gile
in reply to: rui_pestana2

Hi

Vector3d.GetAngleTo method is overloaded

vec1.GetAngleTo(vec2) always returns an angle in the range [0, pi]

vec1.GetAngleTo(vec2, referenceVector) returns an angle in the range [0, 2*pi], where referenceVector is the normal vector of the reference plane.

Following your example, if the referenceVector is (0.0, 0.0, 1.0), according to the "right hand rule",

(acVector2.GetAngleTo(acVector1, referenceVector)) * 180 / Math.PI
returns 135.0

(acVector1.GetAngleTo(acVector2, referenceVector)) * 180 / Math.PI
returns 225.0


Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Message 3 of 4
rui_pestana2
in reply to: rui_pestana2

Salut Gile

Votre réponse a été très utile mais si vous regardez ce exemple en bas:

Sub TestVector3DAngles()

Dim referenceVector As New Vector3d(0, 0, 1) 'normal à XY plane
Dim VectorX As New Vector3d(1, 0, 0) ' X axe

Dim v1 As New Vector3d(1, 1, 0) ' 45 degrés
Dim v2 As New Vector3d(-1, 1, 0) ' 135 degrés
Dim v3 As New Vector3d(-1, -1, 0) ' 225 degrés
Dim v4 As New Vector3d(1, -1, 0) ' 315 degrés

Dim Ang1 As Double = v1.GetAngleTo(VectorX, referenceVector) * 180 / Math.PI 'Retours 315

Dim Ang2 As Double = v2.GetAngleTo(VectorX, referenceVector) * 180 / Math.PI 'Retours 225

Dim Ang3 As Double = v3.GetAngleTo(VectorX, referenceVector) * 180 / Math.PI 'Retours 135

Dim Ang4 As Double = v4.GetAngleTo(VectorX, referenceVector) * 180 / Math.PI 'Retours 45

End Sub

Les retours sont les angles anti-horaires. J'ai changée le 'referenceVector' à l'axe -Z ('normal à YX plane) et le retour est le correcte.


Merci bien,

Rui Pestana
Message 4 of 4
_gile
in reply to: rui_pestana2

Hi,

Try:

Dim referenceVector As New Vector3d(0, 0, 1) 'XY plane normal
Dim VectorX As New Vector3d(1, 0, 0) ' X axis (from vector)
Dim v1 As New Vector3d(1, 1, 0) ' 45 degrees (to vector)

Dim Ang1 As Double = VectorX.GetAngleTo(v1, referenceVector) * 180 / Math.PI 'Returns 45


Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

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