What would be the best way to initialize a Multiple array (1,2,3) within an array (1,2,3) within an array(1,2,3)?

3 Years
Discussion Span
Last Post by Lee Stone

I'm not sure I understand exactly what you're asking, but initialization lists can be nested:

int foo[2][2][3] =
        {1, 2, 3},
        {1, 2, 3}
        {1, 2, 3},
        {1, 2, 3}

If the values of the array aren't known at compile time then you're stuck with some variation of looping through every element and initializing it at runtime.


This being C++, there are ways of doing whatever you're doing that are much easier for you to keep track of and think about. Does it have to be a 3D naked-array of 3D naked-arrays of 3D naked-arrays? If you're actually modellings a groups of somethings, each of which contains another group of something-elses, using proper C++ classes (which will then take care of their own initialisation) will make it easier to think about, easier to code, and easier to maintain.


How do you keep track of all the stars in the solar system and their position to calculate from one point to at least 3 stars to insure you are on the right course in space.


Here's literally the first thing I thought of.

object type: star
internals: location in space; x, y, z

Each star to represent is a single star object. Every star you use goes into a single store of some kind. An array of stars, or a list, or a vector, or some other storage.

So now you have a single array of star objects. Each star object has an x, y, z location.

Create a function to define the line that goes through any one location (i.e. where you are) and any one star (this is a standard mathematical operation). Given that you don't know where you are, you will have angles to the star as input and the line as output. Also given that you have no absolute zero degrees, one of the stars will be your zero degrees reference point.

Create three of these lines. You can use any three stars, but stars at right angles to each other will give the least error.
Create a function to examine the three lines and establish where they cross (you can do this with two lines, but if you want to do it with three, you'll get less error; this is also a standard mathematical operation).

So, one new type; starObject.
One array of starObjects (which is a one-dimensional array).
Two new functions (define line given one point and angle of line from it, and find crossing-point of three lines).

The difficultly here is not in programming it; the difficulty is in ensuring you understand the mathematics of looking at three objects and establishing your location from them, knowing only their positions in space relative to each other. Even if you already know how tio do this, I strongly recommend doing it on paper with two points to check the maths, and then extend that to three points.

Edited by Moschops


This is great and simple, but what if you were on the other side of the Milkey Way? Would you be able to see the same stars? Or would you have to use others. What are their location(s) in relation to all the other stars and how do you identify them or their location so that you can calculate your location. This is the begining of a lot of questions, if you get my drift.....

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.