Welcome, Guest. Please login or register.

Author Topic: Trigonometry Question  (Read 3871 times)

Description:

0 Members and 1 Guest are viewing this topic.

Offline Cymric

  • Hero Member
  • *****
  • Join Date: Nov 2002
  • Posts: 1031
    • Show all replies
Re: Trigonometry Question
« on: May 18, 2008, 08:00:33 PM »
It's fairly simple trig, but what do you supply as input?
Some people say that cats are sneaky, evil and cruel. True, and they have many other fine qualities as well.
 

Offline Cymric

  • Hero Member
  • *****
  • Join Date: Nov 2002
  • Posts: 1031
    • Show all replies
Re: Trigonometry Question
« Reply #1 on: May 18, 2008, 08:52:17 PM »
Ok. For a unit circle located on the origin, the coordinates of point P are simply (assuming that cos() and sin() take radians instead of degrees):

   P_x = cos(angle * \pi / 180)
   P_y = sin(angle * \pi / 180)

The radius of the circle is now R, and the origin is at (O_x, O_y), meaning that point P now resides at

   P_x = O_x + R * cos(...)
   P_y = O_y + R * sin(...)

If cos() and sin() take degrees, you can omit the \pi * 180 correction factor. Good luck!

Some people say that cats are sneaky, evil and cruel. True, and they have many other fine qualities as well.
 

Offline Cymric

  • Hero Member
  • *****
  • Join Date: Nov 2002
  • Posts: 1031
    • Show all replies
Re: Trigonometry Question
« Reply #2 on: May 24, 2008, 09:44:55 PM »
Well, a sphere is something else again. You need 3 coordinates to locate a point on a sphere: two are angles, and one is a distance. The first angle is to indicate how far you should rotate in the plane going through the center of the sphere. Think of an orange you slice in two, and then trace the outer rim of one half. The other angle indicates how much up or down you should go---on the orange, once you've selected a point on the rim, trace from there to the  top (or bottom) of the fruit following the outer surface. The distance then simply moves a specified amount outward.

Assuming that the first angle is called \alpha and the second \beta, with distance R, then your formulas will then become:

P_x = O_x + R * cos(\alpha) * sin(\beta)
P_y = O_y + R * sin(\alpha) * sin(\beta)
P_z = O_z + R * cos(\beta)

Keep in mind that the definition of \beta is a little awkward: 0 degrees is straight up; 180 degrees is straight down. If you prefer to go with he more familiar 90 degrees straight up and -90 degrees straight down (note the minus!) then you should calculate

\beta_0_to_180 = 90 - \beta_90_to_90

first before inserting \beta_0_to_180 straight into the above equations. 3D geometry is a lot more complex than 2D geometry, as you can see.
Some people say that cats are sneaky, evil and cruel. True, and they have many other fine qualities as well.
 

Offline Cymric

  • Hero Member
  • *****
  • Join Date: Nov 2002
  • Posts: 1031
    • Show all replies
Re: Trigonometry Question
« Reply #3 on: May 27, 2008, 07:24:50 AM »
Quote
This is getting annoying now. Basically I'm making a 3D space game. I'm new to 3D programming.

3D programming is a very different kind of animal than is 2D. I'm not sure this simple math is sufficient to get your ideas off the ground, really.

Quote
I want to make my spacecraft be able to rotate on all axis (which is simple) and be able to fire thrusters in any direction (on all axis). Its this problem which is halting my project. I've got it to partially work, but it just won't go in the direction the thrusters are facing. Do you have any thoughts? You seem better at maths than me! Once I've got my head around this I'll be happy!

First things first: the 3D formulas I gave above assume degrees as angle units. If your version of cos() and sin() take radians, you need to apply a conversion step just before plugging them into the equations.

Second: your problem has a fairly simply answer. If your thrusters are facing the opposite way of the nose of the ship, then all you need to do is to keep track of where that nose is, and move in that direction. That is, after all, what will happen when a thruster fires. If, on the other hand, you are making a ship with vector thrusts---in other words, where the direction of thrust need not be diametrically opposite to the direction of flight---then things get a whole lot more complex. You need to take into account the fact that the shapeship will not just move forward in space, but rotate on its axis as well. My advice in this case would be to look for this sort of book and work your way from there. But you'll quickly notice that such books do not use simple maths anymore, and for this there is no real remedy.
Some people say that cats are sneaky, evil and cruel. True, and they have many other fine qualities as well.