We are about to switch to a new forum software. Until then we have removed the registration on this forum.
This solution looks pretty simple but I am failing to implement a correct answer.
Nature of Code exercise 6.6 http://natureofcode.com/book/chapter-6-autonomous-agents/
The top left of the grid is -1,-1 and the bottom is 1,1 for PVector rotation.
PVector v = new PVector(____________,____________);
v.______________();
field[i][j] = v;
Thanks
Answers
I am working towards the answer, so choose how much you want to know... :)]
.
.
.
.
.
.
.
.
.
.
The unique aspect for each position is an i and a j where the range is between 0 and cols or rows respectively.
.
.
.
.
.
.
.
.
.
.
You want to create a direction vector. So you probably want to remap those i and j values to the range of (-1, 1) for outward vectors or (1, -1) for inward vectors.
.
.
.
.
.
.
.
.
.
.
You can do this easily with Processing's convenience method map().
.
.
.
.
.
.
.
.
.
.
Once you have done this, you'll notice that the outer values are closer to 1 and the inner values (around the center) are closer to 0. So to have equal magnitude for all vectors you can normalize() them. That way all vectors are of magnitude 1.
.
.
.
.
.
.
.
.
.
.
According to this reasoning the solution to the excercise should be:
Thanks for the step by step breakdown before the final answer!