generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripting Helpers
Home Search
 

Re: Help with relative wind velocity(vector math)

Previous Thread :: Next Thread 
jobro13 is not online. jobro13
Joined: 05 Aug 2009
Total Posts: 2865
01 Jul 2012 07:52 AM
Dear scripters,

I have a problem with a calculator for relative wind speed. As you all know, relative wind speed is the speed of the object to the wind itself. Example: If you are driving with 20 km/h to school with downwind that also is 20 km/h, the relative wind velocity is 0 km/h (Physic guys; Two vectors in the same direction so you can + them!). The other way around (upwind) its 20-20 = 0 km/h (Two vectors, looking in diffrent directions, so you can - them)

This is all simple, but the problem gets in when Angle A ~= 0 or Angle A ~= 180 (in degrees)

Now thats my problem. I have a formula that almost work, but I just know im doing something wrong. The function is currently;

function velocity_wind(W, V, a)
return math.sqrt((math.pow((W*math.cos(math.rad(a))*V),2)+math.pow(W*math.sin(math.rad(a)), 2)))
end

This all looks hard, let me explain. I use phytagoras to get the length of vector A.

W = Wind velocity
V = Object Velocity (in here; the boat)
a = Angle alpha in degrees.

As you all know phytagoras law says A^2 + B^2 = C^2, so C = square root of A + B.

So I need A and B.

Let me rewrite the stuff.

function velocity_wind(W, V, a)
local length_a = math.pow(W*math.cos(math.rad(a)) * V, 2)
local length_b = math.pow(W * math.sin(math.rad(a)), 2)
return math.sqrt(a+b)
end

What I get when angle = 180 (downwind, so relative will be absolute value of W - V) and W = 20 and V = 20 is NOT zero, but 20!?

When doing the same with angle 0 I get 20!? (which must be 40!?)

Someone help!
Report Abuse
jobro13 is not online. jobro13
Joined: 05 Aug 2009
Total Posts: 2865
01 Jul 2012 08:08 AM
Bump.
Report Abuse
thek00lkid is not online. thek00lkid
Joined: 18 Jun 2011
Total Posts: 2778
01 Jul 2012 08:11 AM
And I thought that algebra was bad...
Report Abuse
jobro13 is not online. jobro13
Joined: 05 Aug 2009
Total Posts: 2865
01 Jul 2012 08:15 AM
Algebra is epic. You can really do a lot of cool stuff on roblox, but the problem is that all those noobs here in scripting helpers only are crying about " IWANT A MOVEING DOOR! ADMIN! VIP!" >_>

I am making a real-life game. Im trying to get all laws I know from chemistry, physics everything in it. And this must help, it actually uses something that I have written a week ago; for my physics test I wrote a script on my graphical calculator - fill in the values, you get every value that it can calculate ^_^ (uses formula changing... just put in a table with functions and scriptz do the rest!)

You know what geometry is right? This uses geometry too to calculate the length of the vector A. I dont know if you had forces with physics already, but using that you can get forces on an object when more than 1 force is working on an object ("total force")

Hey, can it be that I have to use -v instead of v? I mean, if math.deg(a) < 90 or math.deg(a) > -90 then v = -v end?

And when math.abs(math.deg(a) == 90 then return math.abs(W - V) end?
Report Abuse
jobro13 is not online. jobro13
Joined: 05 Aug 2009
Total Posts: 2865
01 Jul 2012 08:27 AM
Hmm no I guess it works now.

Upcoming problem - I didnt specify direction now.

God, Now I finally HAVE THE RELATIVE WIND SPEED, now I need to calculate the force on the sail, but for that I need the angle of the wind with the sail...

So uhm the angle of the wind with the boat will be

math.deg(math.acos(((W*cos(a)-v)/math.sqrt((math.pow(W*cos(a)-v),2)+math.pow(W*sin(a),2)))

?
Report Abuse
jobro13 is not online. jobro13
Joined: 05 Aug 2009
Total Posts: 2865
01 Jul 2012 08:28 AM
And with sail will be that angle - 90 degrees.
Report Abuse
jobro13 is not online. jobro13
Joined: 05 Aug 2009
Total Posts: 2865
01 Jul 2012 08:45 AM
Someone?
Report Abuse
TecmagDiams is not online. TecmagDiams
Joined: 18 Sep 2008
Total Posts: 1882
01 Jul 2012 09:24 AM
Why not simply store wind speed in a more appropriate format?

If you store your wind speed as it's X,Y,Z components your calculations are easier, and you can do a lot more with it. In-fact I honestly don't see why you wouldn't have done it this way in the first place. (Also your explanations of physics and math are slightly off :3)

See if you store wind as a Vector3 Value, you can easily preform math on it.

Let's say Wind is (5, 0, 2)
This means it's at an angle blowing along the positive X and Z axis.

Now you have someone moving at a speed of (3, 0, 0)
To get the relative wind speed you simply SUBTRACT (not add, that's an additive total if you had two winds acting on each-other, not a relative speed. Relative vectors are subtracted when in the same direction because they are relative not additive. :3)

This code is literally as simply as (Wind-object.Velocity) which will return a new Vector3 Value of (2, 0, 2), or (Wind.X-Velocity.X, Wind.Y-Velocity.Y, Wind.Z-Velocity.Z)

Since these are Vector values they ALREADY include both speed AND direction. This means wind can be set at ANY speed in ANY direction and it won't matter, the calculations will work. The object could be going at ANY speed in ANY direction as well.

Now the tricky part might be getting this information back into a form of the wind's ray, rather then vector. This is easily accomplished through a few simple checks though. The length of the wind ray is found through a 3 dimensional version of the Pythagorean Theorem, in which:
d = math.sqrt((x^2) + (y^2) + (z^2))

This will return the actual speed of the wind. In my previous example it would be:
d = math.sqrt((2^2) + (0^2) + (2^2))
d = math.sqrt(4 + 4)
d = math.sqrt(8)

And that is the relative wind SPEED (not vector, which we already easily knew and will be the more important thing anyways) for the object.
Report Abuse
jobro13 is not online. jobro13
Joined: 05 Aug 2009
Total Posts: 2865
01 Jul 2012 09:35 AM
I think physics math overtook me this time. You are totally right. I sometimes forget that Roblox is simpler than normal physics xD. This woke me up.

About the actual wind, I will do it else;

I wont use real objects to do so, I store a Vector3Value inside workspace for the wind, it will be calculated by doing random sines and cosines (sines for z, cosines for x, to keep it tidy).

Ex

local start = 0

while true do wait()
start = start + (math.random()-0.5)/100
game.Workspace.Wind.Value = Vector3.new(math.cos(start), 0, math.sin(start))
end

^_^ radians ftw.
Report Abuse
TecmagDiams is not online. TecmagDiams
Joined: 18 Sep 2008
Total Posts: 1882
01 Jul 2012 09:41 AM
Now going on to the question about force on the sail. Using a Vector3 will be more important for that anyways.

The force generated on the sails will be respectively part of the X and Y of the Relative Wind Speed. This ratio is COMPLETELY dependent on the orientation of the sail. (And has nothing to do with the wind speed actually, other then what those portions are coming from.)

The sail should be a brick, included in every Part is a CFrame value. Included in every CFrame is a lookVector, or a vector representing direction. An example is something pointing at a 45 degree angle would have ABOUT (.707, 0, .707). Now if we take our Relative Wind Speed and apply this directional ratio to it (simply multiply RelativeWind*sail.CFrame.lookVector) we will return ANOTHER vector containing the compartmental X,Y,Z forces being applied to the sail. These forces should be all you need to apply since they are TOGETHER the force you want. If you want to know the exact force being applied to the sial in the direction it is going simply preform 3D Pathg on the force vector we just returned.
Report Abuse
jobro13 is not online. jobro13
Joined: 05 Aug 2009
Total Posts: 2865
01 Jul 2012 09:43 AM
Lol im not a noob, I know that in every part is a CFrame value.

I was actually thinking of putting an invisible part at the middle of the sail, so I can calculate the .unit of them. Lookvector is 10 times better so ill use that.

Thanks for all the help ^_^

Report Abuse
TecmagDiams is not online. TecmagDiams
Joined: 18 Sep 2008
Total Posts: 1882
01 Jul 2012 09:45 AM
But ya, storing wind in the workspace as a Vector3Value is the way to go, it let's you create a global wind variable. Clean, nice, fun. :3 And actually normal physics is just as clean, most often times you break a things like Velocities and Forces into the X,Y,Z parts anyways, because it lets you do all your calculations without the worry of angle.

It's always seeing fellow physics enthusiasts about. I always found physics as a second nature. :3
Report Abuse
TecmagDiams is not online. TecmagDiams
Joined: 18 Sep 2008
Total Posts: 1882
01 Jul 2012 09:46 AM
Also you mean your not a newb. A noob could perfectly well know about CFrames and all, a newb however would be new and not. I just wanted to make sure I said it all NOT JUST for you, but for anyone who doesn't understand a whole lot about scripting that may come across this. I actually was going to talk about .unit when I realized that the look vector is already in trigonometric form. :3
Report Abuse
jobro13 is not online. jobro13
Joined: 05 Aug 2009
Total Posts: 2865
01 Jul 2012 10:02 AM
I love physics. I mean, how epic is it to calculate if someone stands on a cliff with x mass on z meters from the centre of it and to calculate if the cliff breaks or not? MOMENTUM LAWS FTW.

I really love it.

And you are right, everyone must know it. I only dont like that in this forum we always get those nooby questions...

"I wanna make a name on a brick HOWWW!?" you know. Getting kinda crazy of it. You can make really epic things on roblox if you understand stuff a bit, and I think if you are 11 you are too young to do epic calculations. I mean, how can you explain what cosine is when they dont even know what a radian is?

I like. Physics!
Report Abuse
NXTBoy is not online. NXTBoy
Joined: 25 Aug 2008
Total Posts: 4533
01 Jul 2012 10:22 AM
You're shooting yourself in the foot by using angles. Just use vectors instead.

    local windVelocity = Vector2.new(10, 10) -- about 14.1m/s north east
    local boatVelocity = Vector2.new(-10, -20) -- faster and closish to south west

    local relativeVelocity = windVelocity - boatVelocity
    local relativeSpeed = relativeVelocity.magnitude
Report Abuse
TecmagDiams is not online. TecmagDiams
Joined: 18 Sep 2008
Total Posts: 1882
01 Jul 2012 10:42 AM
We already went over it NXTBoy. Besides a Vector3 is more appropriate simply because most things in ROBLOX used for these calculations are already in vector 3 values, AND it allows for winds with upwards and downwards forces, if that was desired. (Always go with the more flexible option :D)
Report Abuse
jobro13 is not online. jobro13
Joined: 05 Aug 2009
Total Posts: 2865
01 Jul 2012 11:58 AM
I wont use upward and downward forces, but maybe later for zeppelins or planes I will use that.

Thanks for all the help guys :)
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image