Home   Help Search Login Register  

Author Topic: Placing Objects in a Cone Formation  (Read 572 times)

0 Members and 1 Guest are viewing this topic.

AngusHeaf

  • Guest
Placing Objects in a Cone Formation
« on: 22 Mar 2003, 23:14:31 »
I couldn't think of a better subject, so I apologize. I'm basically trying to do the following...

Get the direction an object is facing in degrees (no problem there) and then put 4 objects on the ground 5m in front of it spaced 30 degrees apart within a 90 degree cone. The part I can't figure out is the trig involved with calculating where the 4 objects go in order to space them correctly. I'm a bit rusty on my high school tangents and cotangents so maybe someone could help me out?

Here's an example of what I want to do...

Object 1 is facing 45 degrees. So I want 4 objects placed in front of it all 5m away, one at 0 degrees, one at 30 degrees, one at 60 degrees, and one at 90 degrees.

I'm a bit lost with the math.
« Last Edit: 22 Mar 2003, 23:15:20 by AngusHeaf »

Offline Sui

  • Former Staff
  • ****
    • OFPEC
Re:Placing Objects in a Cone Formation
« Reply #1 on: 23 Mar 2003, 02:32:59 »
Hmm... possibly something like this:

object2 setpos [(getpos object1 select 0) + sin (getdir object1 + 30) * 5, (getpos object1 select 1) + cos (getdir object1 + 30) * 5,0]
object3 setpos [(getpos object1 select 0) + sin (getdir object1 + 60) * 10, (getpos object1 select 1) + cos (getdir object1 + 60) * 10,0]
object4 setpos [(getpos object1 select 0) + sin (getdir object1 + 90) * 15, (getpos object1 select 1) + cos (getdir object1 + 90) * 15,0]

The bits in bold are the angle (30,60,90) while the bits underlined are the distances (5,10,15).

I'm not too sure if that's what you're after though... I don't think I understood the sort of placings you described (not enough caffine in my diet today ;))...
If that doesn't help, do you think you could clarify what you're after exactly for us please?

AngusHeaf

  • Guest
Re:Placing Objects in a Cone Formation
« Reply #2 on: 23 Mar 2003, 04:38:37 »
If the red square at the bottom of my diagram is the object I'm getting the direction on, then the blue squares are the 4 different objects I want to position in front of it. Notice how the dashed line formed a 90 degree cone. If you divide that cone into 3 then each slice of the pie (so to speak) is 30 degrees. Get the idea? Obviously the problem is that the direction of the first object isn't always going to be a nice number like 0, 90, 180, 360.


Offline Sui

  • Former Staff
  • ****
    • OFPEC
Re:Placing Objects in a Cone Formation
« Reply #3 on: 23 Mar 2003, 12:02:34 »
Ah ha! Just what the doctor (well... I'm no doctor ;D) ordered...

So the angle off (from the normal) on the outer mortar stake is 45 degrees, so the angle off on the inner stake must be 15... (45-15??).

So, the code would look something like this:

stake1 setpos [(getpos mortar select 0) + sin (getdir mortar - 45) * 5, (getpos mortar select 1) + cos (getdir mortar - 45) * 5, 0]

stake2 setpos [(getpos mortar select 0) + sin (getdir mortar - 15) * 5, (getpos mortar select 1) + cos (getdir mortar - 15) * 5, 0]

stake3 setpos [(getpos mortar select 0) + sin (getdir mortar + 15) * 5, (getpos mortar select 1) + cos (getdir mortar + 15) * 5, 0]

stake4 setpos [(getpos mortar select 0) + sin (getdir mortar + 45) * 5, (getpos mortar select 1) + cos (getdir mortar + 45) * 5, 0]

Try that on for size...
Should place them exactly how you specified (hopefully ;D)