| 01-05-2010, 01:26 AM | #1 |
This involves some calculus. I'm working on a spell that has missiles whose movement is governed by parametric equations in the x, y, and z dimensions. Since the missiles will be flying up and down, I want to use a facing angle (x/y) and a pitch angle (x/y - z) to make it look "good". Normally, I'd just use an average rate of change of y displacement divided by x displacement, and it looks fine. But I want to take it an extra step for the hell of it. I took the derivative of the x and y functions in respect to time and divided them (dy/dt / dx/dt) to get a ratio that you can then take the inverse tangent of to get the facing angle. This is the instantaneous and more "accurate" angle, despite the fact that it makes barely any difference. The angle between the collective x/y displacement and the z displacement is trickier. For averages, you could find the x and y displacements between two points in time, take the square root of the sum of their squares, and divide the z displacement by that. But that's not enough either since I'm already using instantaneous rates for the facing angle. I'm stuck on obtaining a formula for this. Part of the reason is that it's difficult to work with infinitesimally small variables like dx and dy and dt. I also don't know where to start, really. The first thing that popped into my head was the formula for the length of a curve - The integral of : SquareRoot(1 + (dy/dx)^2)dx. But there's the annoying dx outside of the square root and I don't want to integrate, I just want to find the instantaneous x/y distance at some given value of t. So I was hoping someone knew anything about this or would be willing to work on it. I think it might be a little out of my depth, but I'm still going to stare at my little diagram. The given values would be: t (duh) x(t) (these are all cubic so setting them equal to t and trying to convert to rectangular would be a bad idea) y(t) z(t) dx/dt dy/dt dz/dt Any help would be appreciated. EDIT: Looking at Wikipedia, there might be something here. I'm going to see if ds/dt = ((dx/dt)^2 + (dy/dt)^2))^(1/2) works. If ds = (dx^2 + dy^2)^(1/2) then if you divide by dt, you can put dt back in the square root as 1/(dt^2). |
| 01-05-2010, 03:19 AM | #2 |
try Atan(z'(t)). |
| 01-05-2010, 01:15 PM | #3 |
Do you want parabolic movement? or are you planning to do something more awesome? |
| 01-05-2010, 02:14 PM | #4 |
Hehe, is that a hermite curve? These are Bezier curves, usually cubic so they have two turning points. Hermite curves seem quite useful so I'll think about it, I like the idea of using vectors to determine initial and final speed. With the bezier format you can only change time intervals to represent acceleration. Is Atan(z'(t)) the way to go? I'll give it a shot when I have time. |
| 01-05-2010, 02:46 PM | #5 |
That's right, Hermite curves but with the time parameter properly defined (t=0 to t = tf; hermite originally works with a "t" parameter between 0 and 1), because they're defined by initial and final position and their respectives velocities, and because those are kinematics variables, therefore you'll have all the kinematic data and calculating the angle is just as Deaod mentioned. |
| 01-06-2010, 07:38 PM | #6 |
I've been thinking about dz/dt, and it definitely seems like that will give you the proper angle. I'm also thinking about making a parametric system where you could specify several different types of curves (trigonometric, hermite, bezier). Just a thought. |
| 01-06-2010, 09:46 PM | #7 |
No, dz/dt is the Z component of the speed. To obtain the Z angle (let's call it elevation angle) you can do it with this formula: vx=dx/dt vy=dy/dt vz=dz/dt EA = atan2(vz; sqrt(vx^2+vy^2)) About your idea of a library for generalized curves, you should try to avoid as much as possible a matrix usage because it will make the code slow. |
| 01-07-2010, 12:55 AM | #8 |
Aha! I knew I was right about the angle. What you just put up is what I came up with earlier. I guess I should have been more specific about the elevation angle. I think for the system I'll have people specify a type of curve and put in some parameters and let the system handle movement and unit enumeration if needed. I don't even know much about matrices but what I figure you're saying is that you could put in some generalized formula for each dimension of the vector and have the script look up that formula and run it. It would probably be more limited than that. |
