Home   Help Search Login Register  

Author Topic: Geomotry and OFP  (Read 737 times)

0 Members and 1 Guest are viewing this topic.

Offline RujiK

  • Members
  • *
  • KoKo Puh-Fizzles!
Geomotry and OFP
« on: 20 Feb 2005, 02:27:06 »
Cos, Sin, atan, atan2

I Cannot get these commands to do as I wish them to!

I simply wish to make an object sit at the LEFT or right of your user no matter what direction you are facing.
I can only get the object to sit in front or behind your user, I cannot get them on the side.
I am not yet old enough to take Geomotry so this is all knew.

Any help would be greatly appreciated.
« Last Edit: 20 Feb 2005, 02:27:29 by RujiK »
I like your approach, lets see your departure.
Download the New Flashlight Script!

Offline Terox

  • Former Staff
  • ****
  • Follow the Sappers!
    • zeus-community.net
Re:Geomotry and OFP
« Reply #1 on: 20 Feb 2005, 12:30:18 »

FDF uses this to deploy their tripods

_w setpos[(getpos Player select 0)+((sin getdir Player)*2), (getpos Player select 1)+((cos getdir Player)*2), 0]

a position is an array and is made up of either 2 or 3 elements

eg
x axis
y axis
height

all you need to do is offset the position of the object to the player after getting the players direction

getdir = gets direction player is facing ( 0 to 359 degrees from north)

(getpos Player select 0)+((sin getdir Player)*2)
sets the x axis position

etc etc


to find out how things work, grab a copy of a de pbo program and decompress scripts.pbo or mission pbo's, thats the easiest way to find out how things are done
« Last Edit: 20 Feb 2005, 12:32:09 by Terox »
Zeus ARMA2 server IP = 77.74.193.124 :2302
Teamspeak IP = 77.74.193.123

Offline THobson

  • OFPEC Patron
  • Former Staff
  • ****
Re:Geomotry and OFP
« Reply #2 on: 20 Feb 2005, 17:50:41 »
Here are some formulae I use:

To convert a relative position into a set of x,y coordinates
(for camera positioning)

if:
x1,y1 are the coordinates of the object
theta is the direction of the object
a,b are the relative position parameters

then
X coordinate = x1 + b*sin(theta) + a*cos(theta)
y coordinate = y1 + b*cos(theta) - a*sin(theta)

__________________________________________________________________________
To find the coordinates of a point in front of or to the side of an object
(these are sub-sets of the formula above)

if:
x1,y1 are the coordinates of the object
theta is the direction of the object
d is the distance of the point from the object

then:
For a point in front of the object
X coordinate = x1 + d*sin(theta)
y coordinate = y1 + d*cos(theta)

(for a point behind use -d or theta + 180


For a point to the right of the object
X coordinate = x1 + d*cos(theta)
y coordinate = y1 - d*sin(theta)

(for a point to the left use -d or theta + 180)

__________________________________________________________________________
To rotate a point about another point.  
This is useful if you select a random point in
a rectangular area, but you want the rectangle to be at an angle, not just north-south, east-west.

if:
x1,y1 are the coordinates for the point about which the rotation takes place
x2,y2 are the coordinates of the original location of the point to be rotated
theta is the angle of rotation

The coordinates of the rotated point are:
x = x1 + (x2-x1)*Cos(theta) - (y2-y1)*Sin(theta)
y = y1 + (y2-y1)*Cos(theta) + (x2-x1)*Sin(theta)


« Last Edit: 21 Feb 2005, 08:27:31 by THobson »

Offline RujiK

  • Members
  • *
  • KoKo Puh-Fizzles!
Re:Geomotry and OFP
« Reply #3 on: 21 Feb 2005, 01:56:49 »
Thats a GREAT idea! Thanks Thobson!
I never would have thought to add the dir of my unit!

(Also to Terox that is what I was doing origanally but thanks anyway.)
I like your approach, lets see your departure.
Download the New Flashlight Script!

Offline ACF

  • Members
  • *
  • Llama?? Ain't that French for tanks?
Re:Geomotry and OFP
« Reply #4 on: 21 Feb 2005, 13:57:22 »
? (!Like trig): Goto "hereendeththelesson"

The following creates the absolute grid coordinates of a point from polar coordinates (distance + angle) relative to the position and direction of the origin object. It is, of course, related to THobson's:

Quote
X coordinate = x1 + d*sin(theta)
y coordinate = y1 + d*cos(theta)
but does away with the need to think about and change the formulae for the different directions. The trick is to add the target's direction to the origin's heading, so our formulae become:

x coordinate = x1 + d*sin(omega + theta)
y coordinate = y1 + d*cos(omega + theta)

Where omega can be considered the origin's facing and theta the relative direction of the target position. Logically, if I'm facing East (+90 degrees) and want an object on my left (+270 degrees from MY heading), the target object wants to be North of my position (360 = 90 + 270):

#hereendeththelesson
For trigonometrophobes, here's the script form:

Code: [Select]
_targetx = (GetPos _origin) Select 0 + (_distance * Sin (GetDir _origin + _reldir))
_targety = (GetPos _origin) Select 1 + (_distance * Cos (GetDir _origin + _reldir))
_targetpos = [_targetx,_targety,0]
_origin = your starting unit/object
_distance = the distance to the target position
_reldir = the relative direction of target position in degrees FROM THE DIRECTION _origin IS FACING, e.g.
  Front: _reldir = 0
  Right: _reldir = 90
  Rear:  _reldir = 180
  Left: _reldir = 270
  Half right: _reldir = 45
  . . . and so on.

Offline RujiK

  • Members
  • *
  • KoKo Puh-Fizzles!
Re:Geomotry and OFP
« Reply #5 on: 22 Feb 2005, 18:59:46 »
Well thanks for the help however I found a way to make an object to the left (or right) of you, after all that complex scripting I found a simple way  ;D

Here it is:

Code: [Select]
_obj = _this select 0

_xdefault = getpos player select 0
_ydefault = getpos player select 1
_x = _xdefault-((cos getdir player)*1.2)
_y = _ydefault+((sin getdir player)*1.2)
_obj setpos [_x,_y,0]

Yep, thats it very easy, all you have to do is subtract the cos and add the sin, or vise versa.
« Last Edit: 22 Feb 2005, 19:00:42 by RujiK »
I like your approach, lets see your departure.
Download the New Flashlight Script!