Home   Help Search Login Register  

Author Topic: Relative angles and distances issue  (Read 3500 times)

0 Members and 1 Guest are viewing this topic.

Offline Trexian

  • Members
  • *
Relative angles and distances issue
« on: 02 May 2010, 04:30:21 »
Ok.  I'm basically having a problem with trigonometry.  I searched, and found many threads relating to trig, but couldn't discern any answers to my problem - although I admit it just may not have been obvious to me.  Also, I may be making this more difficult than I need to, so any alternative solutions are much appreciated, also.

First, to define the problem: I want to generate positions within a marker, but the marker direction may not be straight north.  A bit more information: I received a nifty little script that will generate random gaussian numbers; that is, you define the average and the standard deviation, and the function will generate numbers that will fall on a bell curve. The website for the basic idea for the function is
here.

My "solution" was to start at the center, move "north" - the direction of the marker (relative to the center) - the distance of radA (from the returned markerSize), then "west" to get to the "top, left" corner of the marker.  Then, use the gaussian random to generate x and y distances in the directions "east" and "south."

To test, I started by just using the location and direction of my player character.

Here I am.


If I face due north, it works pretty well.


The blue markers reflect where I anticipate the north/top corners of the rectangle to be.

Same thing if I change the equation a bit, and use my center location to generate the gaussian randoms.


For testing, here's what happens if I use purely random distances along x/y.


Anyway, if I offset my player by about 45 degrees, things go to $4!7.  As you can see, the blue markers are messed up, and the gaussian randoms seem to be scrunched between the 2 blue markers.


If I use my position as center, and gaussian random the distances away from me, in purely random directions, I get somewhat better results, but the axis is clearly north/south, and not angled in the direction I'm facing.


I am using the "standard" way to determine the new positions:
For the blue markers:
Code: [Select]
// create markers for startpoint
_startMarker = createMarker ["startPoint", [_stPtX, _stPtY]];
_startMarker setMarkerShape "ICON";
_startMarker setMarkerType "dot";
_startMarker setMarkerColor "ColorBlue";

_ePtX = (_stPtX) + sin (_dirE) * _distX;
_ePtY = (_stPtY) + cos (_dirE) * _distY;
_eastMarker = createMarker ["eastPoint", [_ePtX, _ePtY]];
_eastMarker setMarkerShape "ICON";
_eastMarker setMarkerType "dot";
_eastMarker setMarkerColor "ColorBlue";

For the gaussian random using the top/left starting point:
Code: [Select]
// distances X and Y
// gRand all marker
_grX = [_avgX, _stDevX] call JTD_f_gRand;
_grY = [_avgY, _stDevY] call JTD_f_gRand;

// get coords
_grPtX = (_stPtX) + sin (_dirE) * _grX;
_grPtY = (_stPtY) + cos (_dirS) * _grY;


For the gaussian random using my own position:
Code: [Select]
// this routine uses the center position, with random direction
_grX = [.1, _stDevX] call JTD_f_gRand;
_grY = [.1, _stDevY] call JTD_f_gRand;

// get coords
_dir = random 360;
_grPtX = (_pos select 0) + sin (_dir) * _grX;
_grPtY = (_pos select 1) + cos (_dir) * _grY;

I hope I've been relatively clear in stating my problem. :)

Thanks!
Sic semper tyrannosauro.

Offline Inkompetent

  • Members
  • *
Re: Relative angles and distances issue
« Reply #1 on: 02 May 2010, 17:55:24 »
For angled markers I suggest the simple solution of working with the marker as if it wasn't angled at all. After you have got your random position in the marker, then take the angle into consideration by rotating the generated point around the marker center by the markerDir amount.

I'm somewhat stuck myself in the trigonometry always causing something else to go wrong when I fix another problem. Got to say I totally love those well-spread patterns though!

Offline Trexian

  • Members
  • *
Re: Relative angles and distances issue
« Reply #2 on: 06 May 2010, 05:10:31 »
Well, ladies, welcome to Trexians Wonderful World of Half-Assed Inelegant Solutions, or TWWoHAIS for short.... (not sure which one is harder to pronounce).... :)

Inko - I tried something like you suggest, but it came out more or less centered on the start point, or distributed just awkwardly.  I'm not sure I really understood you solution, but THANKS for offering it. :)  It did get my creative juices flowing.



What I ended up doing (after fixing the dufus-esque mistake on finding the NorthEast corner) is making it a 2 step process.  First, find a point that is a gaussian random distance in the X axis along the North edge of the map, then get another gaussian random point South.  The idea is that since both numbers should represent a bell curve distribution, the "total" will also be.

It doesn't quite work out that way, but frankly (and this may be rationalization) I like it better.  It seems more distributed in the X axis.  But, it represents something between totally random and a totally predictable bell curve.  The chance of statistical out-fliers is increased.

The sqf tidbit:
Code: [Select]
// make it a 2 step process - first get X distance in East direction, then go Y distance South
_grX = [_avgX, _stDevX] call JTD_f_gRand;
_grY = [_avgY, _stDevY] call JTD_f_gRand;

_tPtX = (_stPtX) + sin (_dirE) * _grX;
_tPtY = (_stPtY) + cos (_dirE) * _grX;

_grPtX = (_tPtX) + sin (_dirS) * _grY;
_grPtY = (_tPtY) + cos (_dirS) * _grY;

Hope that helps someone in the future. :)
Sic semper tyrannosauro.

Offline Inkompetent

  • Members
  • *
Re: Relative angles and distances issue
« Reply #3 on: 07 May 2010, 17:13:29 »
That looks like a really beautiful pattern.

However, in what addon/script pack can I find the JTD_f_gRand function?

Offline Trexian

  • Members
  • *
Re: Relative angles and distances issue
« Reply #4 on: 07 May 2010, 17:36:49 »
It isn't out, yet. :)

I'll PM to you what I have now.  I'm still wondering if there are tweaks to it.
Sic semper tyrannosauro.