Angle between 2 vectors
3 posts • Page 1 of 1
Angle between 2 vectors
In many cases I need to calculate signed angle between 2 vecs.
I do some maths and it can be handy for you:
I do some maths and it can be handy for you:
- Code: Select all
// Scalar multiplication
Scene.my.vpr2 := (v1, v2)=>{v1(0) * v2(0) + v1(1) * v2(1)};
// Length
Scene.my.vmod2 := (v)=>{(v(0) ^ 2 + v(1) ^ 2) ^ 0.5};
// Determinant
Scene.my.opm2 := (m)=>{m(0)(0) * m(1)(1) - m(1)(0) * m(0)(1)};
// Angle
Scene.my.va := (v1, v2)=>{(scene.my.opm2([v1, v2]) >= 0 ? 1 : -1) * math.acos(scene.my.vpr2(v1, v2) / scene.my.vmod2(v1) / scene.my.vmod2(v2))};
//Example
Scene.my.va([1,1],[0,10])
//gives 0.7853982 (pi/4)
Dream of Algodoo as game development engine...
-

Kilinich - [Best bug reporter 2010]
- Posts: 2098
- Joined: Mon Aug 31, 2009 8:27 pm
- Location: South Russia
Re: Angle between 2 vectors
NIce theese could be very useful. I think I use pythagora's method. I can't really remember the name 
-

Rideg - Posts: 948
- Joined: Tue Dec 15, 2009 5:17 pm
- Location: Östersund, Sweden
Re: Angle between 2 vectors
Do you mean Pythagoras theorem? Part of his code use that anyway.
Anyways it's actually a quite useful piece of code
Anyways it's actually a quite useful piece of code
-

Mystery - Posts: 2802
- Joined: Thu Sep 03, 2009 1:16 pm
- Location: Southern Australia
3 posts • Page 1 of 1
Who is online
Users browsing this forum: No registered users and 3 guests




