Angular Velocity

Posted By: fastlane69

Angular Velocity - 05/08/03 04:04

I'm trying to get an angular velocity reading fromt he phent_getvelocity() function. According to manual:

----------------------------------------------
If pointLocal is (0,0,0) this returns the linear velocity of the object. Otherwise it's a combination of linear and angular velocity at the given distance from the center.
-------------------------------------------------

How I read this is that if I place my vecpointlocal on my center of mass, I only get a linear velocity reading. Makes sense and works.

However, if I displace vecpointlocal, say 100 units on the x-axis, I expect to get some angular velocity information. I have torqued my entity, it's actually rotating, but I'm getting no angular velocity information. I have tried several approaches and nothing.

Is it angular velocity or tangential velocity that is returned when vecpointlocal DNE null?

(Vangular= Vtangential/Radius)

Since you have to displace vecpointlocal to get an "angular" velocity reading, I suspect it's tangential, not angular.

I've tried vec_to_angle() on vecoutvelocity while rotating but not displaceing and nothing.
Posted By: Anonymous

Re: Angular Velocity - 05/08/03 06:10

It should be tangential velocity: vLinear+ (Crossproduct(vAngular x vDistance))

I have tested this function a while ago and it worked. Let me check if it has become broken..
Posted By: fastlane69

Re: Angular Velocity - 05/08/03 13:18

Just so I understand, to get angular velocity:

a) Get linear velocity at vecpointlocal = (0,0,0).

b) Get a velocity at vecpointlocal =(100,0,0).

c) Subtract a) from b). This leaves me with tangential velocity.

d) Divide result by radius, in this example, 100.

This is what I think I'm doing with:

----------------------------------------
//fixed_ang is a vector set to 100 units
//on the x axis. null_vec is zero.

phent_getvelocity(my,temp_vel1,null_vec);
phent_getvelocity(my,temp_vel2,fixed_ang);

//Subtracting a) from b)
vec_sub(temp_vel2,temp_vel1);

//Dividing by distance (100 units)
vec_scale(temp_vel2, .01);

//Copies into a skill displayed on panel
vec_set(player.ang_velocity_x,temp_vel2);
-------------------------------------------

......and nothing. I pick up linear velocity fine, but no angular velocity what so ever when I torque my entity up with addtorquelocal.
Posted By: fastlane69

Re: Angular Velocity - 05/09/03 07:30

Anyone else use the phent_getvelocity function? If so, are you getting a reading when vecpointlocal DNE 0?

I swear I'm getting nothing or just plain don't understand how to get an angular velocity from the _getvelocity function...
Posted By: Anonymous

Re: Angular Velocity - 05/09/03 08:25

@fastlane:
Your algorithm seems right, so it should be working. This problem is on my list of things to check, but that list has some 10 other entries in front of it [Frown]
Posted By: fastlane69

Re: Angular Velocity - 05/09/03 08:46

Hi Marco

Thanks for your personal attention on the matter.

Totally understand your busy... compounded by the fact that not many people are using said feature.

We'll see if some solution doesn't present itself soon. Could be some local vs. global issues, I don't know.

Thanks and look forward to your reply!!!
In the meantime, if any users have any advice, please please pose! [Smile]
Posted By: Anonymous

Re: Angular Velocity - 05/09/03 10:24

My mistake. A6.0 ignores the location parameter, and thus returns the value for phent_getvelocity(myObject, temp, vector(0,0,0));
This will be fixed in A6.1
Posted By: fastlane69

Re: Angular Velocity - 05/09/03 14:07

Gotcha!

Thanks Marco.... will start working on a stop gap solution in the meantime....
Posted By: fastlane69

Re: Angular Velocity - 03/04/04 09:27

It's been 10 months now and 6.1 is here and gone, so it's time to reopen this thread.

1) Off-center phent_getvel() does seem to be working now. When I use the approach above (sample at center and offset; subtract and rescale), I do get what seems to be a constant angular velocity....but...

2) This velocity seems to be what I can best describe as globally referenced (?). Hence, I may see ang_velocity_x at 35 q/s and zero ang_velocity_y and later my ang_velocity_y is at 35 and _x is at 0, which is consitent with a tangential angular velocity vector attached at a fixed radius and rotating relative to a global fixed coordinate system.

Short of calculating the speed and then artificially inserting a direction, is there anyway that I can get angular velocity relative to a euler angle or relative to a local coordinate? I would really like to make one call and get a singular constant value; so if I'm rotating perfectly around the z-axis, similar to the ubiquious figure skater doing turns, I could get a constant value for their rotational speed and not a constantly changing one.

I know the mathematical way get a constant value; just want to know if there is an easy call or couple of calls I can make and avoid some of the nasty maths that will crop up in dealing with cross products. Or perhaps I'm missing the point altogether; either way, I'd like to hear what others and Conitec has to say.

Posted By: feature_creature

Re: Angular Velocity - 03/10/04 13:28

I think you're right.
The formula above gives the tagential velocity only if the angular velocity vector is perpendicular to the vector from the origin to the point being tested (radius).

It is much more complicated in the general case.

It seems easier to manually keep track of the angular difference between the last frame and the current frame and divide by time -- voila: angular velocity in degrees per second.

One thing I notice about this last method:
It works fine when I don't have physics turned on.
But when physics is turned on, and I set damping to 0, gravity to 0, and apply an initial torque in more than one direction -- the angular velocity is not constant.

This makes me suspicious about the physics system!

This code produces results I would expect:
Code:

string db[15];

action rotate {
var prev[3];
var total = 0;
vec_set(prev,my.pan);

while(1) {
vec_diff( temp, my.pan, prev );
vec_set(prev,my.pan);
vec_scale( temp, 1/time );
total = vec_length(temp);

str_for_num( db, total );
draw_text( db, 50, 170, vector(100,100,255));

str_for_num( db, temp[0] );
draw_text( db, 50, 50, vector(255,100,100));
str_for_num( db, temp[1] );
draw_text( db, 50, 90, vector(255,100,100));
str_for_num( db, temp[2] );
draw_text( db, 50, 130, vector(255,100,100));

my.pan += 3*time;
my.tilt += 3*time;
my.roll += 3*time;
wait(1);
} //while

} //



Here is the "equivalent" with physics:
Code:

action physics_rotate {
ph_setgravity( nullvector );
phent_settype( my, PH_RIGID, PH_BOX );
phent_setmass( my, 1, PH_SPHERE );
phent_setdamping( my, 0, 0 );

var prev[3];
var total = 0;

vec_set(prev,my.pan);

phent_addtorqueglobal( my, vector( 30, 30, 30 ) );

//for this to work make sure object is not on the floor
while(1) {
vec_diff( temp, my.pan, prev );
vec_set(prev,my.pan);
vec_scale( temp, 1/time );
total = vec_length(temp);

str_for_num( db, total );
draw_text( db, 50, 170, vector(100,100,255));

str_for_num( db, temp[0] );
draw_text( db, 50, 50, vector(255,100,100));
str_for_num( db, temp[1] );
draw_text( db, 50, 90, vector(255,100,100));
str_for_num( db, temp[2] );
draw_text( db, 50, 130, vector(255,100,100));

wait(1);
} //while

} //



The physics version fluctuates much more -- even with mass type set to PH_SPHERE.

Now, with the same settings and mass type set to PH_BOX, the model will actually spin out of control and then freeze within a few seconds. I know that this has something to do with setting damping to 0, but that would be case in a space game, right?

So, even if your code accurately measures angular velocity, when you're using physics, it will still fluctuate a lot so it may not be a reliable measure for determining how constant angular velocity is.

That's enough research for one night!

(Should be 1/time -- not time!)





Posted By: fastlane69

Re: Angular Velocity - 03/10/04 16:55

Problem is that if I now what to also record angular acceleration, I would have to set aside 12 extra skills: 6 skills to keep angular position and calculate velocity and 6 skills to store angular velocity and calculate acceleration. But your point is well taken and I may have to do this for now
Posted By: Marco_Grubert

Re: Angular Velocity - 03/12/04 05:19

I am hoping to be done with c_move anytime now, after that the physics engine will get a major overhaul and your suggestions/bugreports are appreciated. I will post another message here so the bugs which "slipped past my watch" will get a chance to be addressed.
Posted By: fastlane69

Re: Angular Velocity - 03/12/04 05:30

Well met and thanks Marco. I've been a devotee of the 3DGS PE since hour one and would be thrilled at having input into it's next generation.

Until then I trust you don't take our continued posts as personal requests, but rather as an ongoing record of the current PE. Given your statement, we'll be anxiously waiting for your go ahead before we unleash our TRUE wishlist...heheeheh

Thanks for the current PE and the future ones !

Posted By: William

Re: Angular Velocity - 03/14/04 16:36

I have a few items on a physics engine wish list myself. Please tell us when you start re-vamping the physics engine. Thanks Marco, Best of Luck.
Posted By: feature_creature

Re: Angular Velocity - 04/01/04 04:32

Please excuse my mis-posting.
Posted By: Marco_Grubert

Re: Angular Velocity - 05/05/04 11:01

Currently this is how it works: rotation is stored as axis of rotation with vector magnitude expressing speed of rotation. phent_getvelocity() returns the following vector: tang_vel = lin_vel + ang_vel x (Rot*point)
Where lin_vel is linear velocity in global coordinates, ang_vel is the above mentioned vector (global), Rot is the entity's rotation matrix and point is the passed in local coordinate.
Since point gets rotated depending on the object's orientation constant angular velocity will yield varying tangential velocity. For example given an object spinning counter-clockwise around z, when point=(1,0,0) the tangential velocity at (1,0,0) will initally be returned and be (0, 1, 0). At the next frame, however, the local point (1,0,0) has been rotated by 90 degrees and is now at (0, 1, 0) and the corresponding tangential velocity vector is (-1,0,0). Next frame: (-1, 0, 0) point with (0, -1, 0) tang_vel.

Is this useful behavior ? If not what kind of information would you like to have returned ?
Posted By: fastlane69

Re: Angular Velocity - 05/05/04 11:59

Quote:

Is this useful behavior ? If not what kind of information would you like to have returned ?




My only problem is that there are more situations where I want the angular velocity rather than tangential velocity; I suspect this might be the case with most of us.

As such, with the exception of a sphere or cube that have a Unitary Moment of Inertia, solving for angular velocity for arbritrary geometries becomes cumbersome or downright impossible without Matrix Algebra.

IMO, it would be better if you could obtain rpm directly instead of m/s.
Posted By: Marco_Grubert

Re: Angular Velocity - 05/06/04 05:15

The idea behind phent_getvelocity() was to find out how fast a certain point is moving. When you bump into another object you can call getvelocity in the event function to determine if it was a high-speed crash or just a minor dent.
For this purpose it would be more useful to specify the point in global coordinates...
I could easily return the angular velocity vector - would that help ?
Posted By: fastlane69

Re: Angular Velocity - 05/06/04 05:45

Quote:

The idea behind phent_getvelocity() was to find out how fast a certain point is moving. When you bump into another object you can call getvelocity in the event function to determine if it was a high-speed crash or just a minor dent.





Which is perfect for Linear collisions, but, and this is just my opinion, it doesn't seem to be so hot for rotational collisions.

Question: How is rotational collsions handled?

For eg, I have two thik disks rotating about their z-axis (vinyl record like). As I bring their edges, together slowly, adiabatically (so as to minmize the linear collision dynamics), at some point the edges come into contact and the collision is purely rotational. By my current understanding of the PE a tangential velocity will be calculated for each of the points of contact and then some kind of momentum conservation is done? By your words then, this is done on global coordinates...how is this then translated to local motion???

Im thinking that perhaps, alot of the jitters and other myriad of collision bugs could in fact be due to inconsistencies in the rotational collision or in the handling of rotations?



Quote:

I could easily return the angular velocity vector - would that help ?




I would much rather display three ang vel vectors (omega(about z), omega(about y), and omega(about x)) and if I'm constantly rotating about z, for eg, omega(z) would remain constant and the others zero. This is motivated in part by the fact that when I torque an entity, I do so about a local axis. Thus, one can see a positive corrolation between ang vel change (ang acc or alpha) and applied torque. In the above record example, if I had two columns, one for torque(about axis) and another for alpah(about axis), I could for example see a "10" in the z-torque column and then see that my ang_vel(about z) is steadily increasing.

When it comes to car physics, if these omegas are local, then you align the x axis with the front of the car. If omega(x) gets too out of hand, you can either pause the physics engine and my.roll it back into place or keep the PE on and torque it back into place.


BUT THATS JUST ME.....OTHERS NEED TO SPEAK ON THIS ISSUE TO REALLY GAUGE WHETHER THIS IS THE BEST WAY TO GO AND IF ANYTHING i SAID MAKES SENSE .
© 2024 lite-C Forums