jPCT-AE - a 3d engine for Android > Support

Info on calcAngle on SimpleVector

(1/2) > >>

Ulrick:
Hi all,

just a quick question.

Probably in known to everyone, but I cannot understand why calcAngle return a 180 degree angle (I mean values from 0 to 180).

It could be possible to have it 360 degrees (means from 0 to 360)? or from -180 to +180?  Otherwise, how can I calculate angles from 0 to 360 between two SimpleVectors?

Probably I missed something.

Thanks in advance,

Ulrick

EgonOlsen:
It's simply the closest angle between two SimpleVectors and it has no direction, i.e. the angle between a and b is the same as between b and a. And it never exceeds 180°, because it's the closest angle...and that can't be larger than 180°. The actual formula is simple (in pseudo code):


--- Code: ---nv1=norm(v1)
nv2=norm(v2)

d=dot(nv1, nv2)

angle=acos(d)

--- End code ---

If you need something else, google might be your friend. I've already tried briefly, but i couldn't come up with something really better...just with different solutions to do the same thing...

What do you want with that angle? Maybe there's another solution!?

paulscode:
360 degrees doesn't make sense when you consider the fact that the two vectors can be any orientation.  There are always going to be two arcs you can measure angles for (and if you know one you know the other since they add to 360 degrees).  How would you specify which arc is the one you want to measure?  That's a question which depends on each particular project.  You have to take the information jPCT gives you and decide which arc you are looking for.  I can probably help with this if you let me know what you are after (I've used this extensively in the auto navigation system I wrote for the game I'm working on).

Ulrick:
You are right, but do you think could be possible to add also a direction vector in calcAngle in order to have a 360 degree angle evaluation?

What I actually need is to get a space orientation in the 3D world of an object. This is needed to have a correct rapresentation of a map view when moving in all direction of the surrounding elements.

As an example, image to have a space game where a ship can move in any direction, How do you represent a radar view of enemy ships? imagine that you could be upside down or on one side while moving in space.

-- Update --
Actually, would be interesting, and I believe usefull, to have an extended class of the SimpleVector witch take into account also the direction vector.

-- Update2 --

After the suggestion of EgonOlsen and the description on how does it work, I found out a possible work around, but I will need to work on it to make it in one step.

What I do is the following:

SimpleVector V1=plane.getTransformedCenter();
SimpleVector V2=cam.getDirection();
                     
V1.y=0;
V2.y=0;
                     
float Angi= (float) (Math.atan2(V1.normalize().z,V1.normalize().x)-Math.atan2(V2.normalize().z,V2.normalize().x));

This should work for me. Do you think it is ok? The radar view is just a "top view" of the area and surrounding elements are displayed smaller if at a lower altitude or bigger if higher.         

Anyway both of you gave me already a good hint to start on.

Thanks a lot,

Ulrick

paulscode:
That looks like it should work.  I came up with another way to do something similar to this (a single-axis billboarding effect I needed to add glow effects to cylindrical objects).  In case you run into any issues with your formula, I can give you another way to do the same thing.

Navigation

[0] Message Index

[#] Next page

Go to full version