Skip to main content
gamedev.net
🔒 Locked

a boat?

Started by dennizzz 6 replies 600+ views
Original Post
dennizzz
dennizzz
if I have a variable containging for example: y = sin(x) I want an object surfe on top of the wave like a boat. I translate it at the y axis with the sinus formula. but how do I derive the formula so i can change the leaning (k) so that it really looks like it is on the top of the sinus. some example?
chowe6685
chowe6685
you could use the derivative to get the slope of the tangent line.
in this case y''(x) = cos(x)
if you need to get the angle then its a little bit trickier but you could just take arctan(y''(x)) = arctan(cos(x))
there is probably a nice simplification of that expression but its a good start
aaron_ds
aaron_ds
I didnt want to try simplifying it by hand so I tried to have my Ti89 do it, unfortunatly accroding to it, arctan(cos(x)) is the simplest form.
I tried arctan(1/cos(x)) just for kicks, but the result endedup being more complex. :-/

90*(pi*sign(cos(x))-pi*arctan(cos(x))/90)/pi
(if anyone cares )
chowe6685
chowe6685
yeah, cos(arctan(x)) is a different story, that simplifies rather nicely

arctan(cos(x)) is about (pi/4)cos(x), but its doesnt sound as though you will be calculating more than once per frame so its probably not worth it
AndyL
AndyL
I don''t meen to complicate things, but doesn''t this assume the boat is quite a bit smaller than the wavelength of the waves?

If the boat were spanning a wave it''d be more complicated, wouldn''t it? Certainly it would tilt more along it''s shortest dimension...
dawid
dawid
Yes Thanks for the Answer i wanted this answer to but isnt it possible to just take the Normal of the Triangle its on and us that to calculate angle?
Spy
dennizzz
dennizzz
yes, but how do you write derivative in c++?

do I have to include any more h file other than math.h?
chowe6685
chowe6685
dawid - yes of course, I just think the code for the derivative is simpler, cross products get messy. It depends on how the data is being stored.

dennizzz - I don''t even think c++ can do formal derivatives, you would have to precalculate them for a given wave. You could also approximate the limit but if you are going to do that it might be just as simple to use dawid''s cross product suggestion

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.