Hi there, I'm relatively new to c++ and I'm trying to write a fairly simple simulation.
The simulation involves updating values in a grid based on the values of neighbouring nodes, and I'm working with polar coordinates.
Say I have an array A[200] and I iterate using an update equation of say;
A[i] = (A[i+1] + A[i-1])/2;
This is fine except at the boundaries, where asking for A[i-1] at i=0 will give a segmentation fault. Due to the periodicity of angles A[i-1] should in fact be A[199] at this boundary.
Obviously I can overcome this with some simple conditionals, but I can't help but feel this must be a fairly common problem and since this is a simulation I want things as concise and quick as possible.
Is there any object already out there which works like an array but loops around at the ends? Or if not does anyone have any ideas of how to elegantly tackle the problem?
Thanks
The simulation involves updating values in a grid based on the values of neighbouring nodes, and I'm working with polar coordinates.
Say I have an array A[200] and I iterate using an update equation of say;
A[i] = (A[i+1] + A[i-1])/2;
This is fine except at the boundaries, where asking for A[i-1] at i=0 will give a segmentation fault. Due to the periodicity of angles A[i-1] should in fact be A[199] at this boundary.
Obviously I can overcome this with some simple conditionals, but I can't help but feel this must be a fairly common problem and since this is a simulation I want things as concise and quick as possible.
Is there any object already out there which works like an array but loops around at the ends? Or if not does anyone have any ideas of how to elegantly tackle the problem?
Thanks
Comment