We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi,
I'm trying to wrap my head around how to go about creating a vector field that spirals toward the center. Here's some basic code I'm working with. cols and rows are the proportional to the width and height.
void init() {
for (int i = 0; i < cols; i++) {
for (int j = 0; j < rows; j++) {
field[i][j] = new PVector(?,?); //
}
}
}
Any help would be awesome - thanks
Answers
Sorry I know that was vague -- I'm actually trying to create a vector field with this type of shape. http://inperc.com/wiki/images/c/c2/Swirly_vector_field.png
a PVector only holds one set of x, y (and z) coords so you'll need two to hold each of those those lines - one for the start and another for the end / direction. unless you're using the i and j for the start point, in which case you'll need some jiggery pokery to translate -ve values into +ve values for your array indices.
as for the values of these vectors, the magnitude appears to change with distance from origin, angle appears to be related to x+y. perhaps something using sin()?
it's question 7 here: http://inperc.com/wiki/index.php?title=Calculus_3:_final which might (*might*) help with the actual equation.
Is there any information carried in the magnitude of the vectors or are they all unit vectors (i.e., same size)?
Either way, you simply create vectors pointing to the center. This will require either a 4D matrix (position & direction) or a 2D quaternian vector (ang, x, y) respectively.
Alternately, you can just use the implicit ang and calculate p.heading() on the fly. It depends what you are doing and if the angles are static or dynamic.
Hi, there is this code from a question in the old forum (not mine, but cant find the thread to give proper credits, as old forum is kind of off line), not really what you need but close, might worth to have a look: