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:
// 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:
// 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:
// 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!