Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c++ > #12052 > unrolled thread

nested for/while loops

Started byahso <ahso47@yahoo.com>
First post2011-12-04 07:04 -0800
Last post2011-12-06 00:03 -0800
Articles 15 — 7 participants

Back to article view | Back to comp.lang.c++


Contents

  nested for/while loops ahso <ahso47@yahoo.com> - 2011-12-04 07:04 -0800
    Re: nested for/while loops ralph <nt_consulting64@yahoo.net> - 2011-12-04 10:32 -0600
    Re: nested for/while loops Nick Keighley <nick_keighley_nospam@hotmail.com> - 2011-12-04 09:23 -0800
      Re: nested for/while loops Victor Bazarov <v.bazarov@comcast.invalid> - 2011-12-04 12:41 -0500
        Re: nested for/while loops ahso <ahso47@yahoo.com> - 2011-12-04 22:56 -0800
          Re: nested for/while loops Werner <werasm@gmail.com> - 2011-12-05 02:13 -0800
            Re: nested for/while loops ahso <ahso47@yahoo.com> - 2011-12-05 06:19 -0800
              Re: nested for/while loops Victor Bazarov <v.bazarov@comcast.invalid> - 2011-12-05 11:59 -0500
                Re: nested for/while loops ahso <ahso47@yahoo.com> - 2011-12-05 23:07 -0800
                  Re: nested for/while loops Ian Collins <ian-news@hotmail.com> - 2011-12-06 20:15 +1300
                  Re: nested for/while loops Nick Keighley <nick_keighley_nospam@hotmail.com> - 2011-12-06 01:37 -0800
                    Re: nested for/while loops ahso <ahso47@yahoo.com> - 2011-12-06 05:02 -0800
                      Re: nested for/while loops "Fred Zwarts \(KVI\)" <F.Zwarts@KVI.nl> - 2011-12-06 16:13 +0100
                      Re: nested for/while loops Victor Bazarov <v.bazarov@comcast.invalid> - 2011-12-06 10:24 -0500
              Re: nested for/while loops Werner <werasm@gmail.com> - 2011-12-06 00:03 -0800

#12052 — nested for/while loops

Fromahso <ahso47@yahoo.com>
Date2011-12-04 07:04 -0800
Subjectnested for/while loops
Message-ID<e9794b78-faec-46e7-bb0f-bfcdaa4438f2@w1g2000vba.googlegroups.com>
Hi
 a function returns Z (height) after giving X and Y location. How
would those two for (or while?) loops look like if I need all z points
in a rectangle.
Many thanks
Michael

[toc] | [next] | [standalone]


#12053

Fromralph <nt_consulting64@yahoo.net>
Date2011-12-04 10:32 -0600
Message-ID<um7nd7p6tm90elpnpk8adipr9djoce944l@4ax.com>
In reply to#12052
On Sun, 4 Dec 2011 07:04:41 -0800 (PST), ahso <ahso47@yahoo.com>
wrote:

>Hi
> a function returns Z (height) after giving X and Y location. How
>would those two for (or while?) loops look like if I need all z points
>in a rectangle.
>Many thanks
>Michael

I'm probably missing something as that question doesn't make any
sense.

Even assuming each "X" and "Y" describes a point. Everything else
would be simple linear addition or substraction.

Need more info.

-ralph

[toc] | [prev] | [next] | [standalone]


#12054

FromNick Keighley <nick_keighley_nospam@hotmail.com>
Date2011-12-04 09:23 -0800
Message-ID<c2b7db78-ee53-4387-8d10-cbc50c2c521c@o1g2000vbe.googlegroups.com>
In reply to#12052
On Dec 4, 3:04 pm, ahso <ahs...@yahoo.com> wrote:
> Hi
>  a function returns Z (height) after giving X and Y location. How
> would those two for (or while?) loops look like if I need all z points
> in a rectangle.
> Many thanks
> Michael

you need to work out how X,Y gets turned into Z

[toc] | [prev] | [next] | [standalone]


#12055

FromVictor Bazarov <v.bazarov@comcast.invalid>
Date2011-12-04 12:41 -0500
Message-ID<jbgbd7$253$1@dont-email.me>
In reply to#12054
On 12/4/2011 12:23 PM, Nick Keighley wrote:
> On Dec 4, 3:04 pm, ahso<ahs...@yahoo.com>  wrote:
>> Hi
>>   a function returns Z (height) after giving X and Y location. How
>> would those two for (or while?) loops look like if I need all z points
>> in a rectangle.
>> Many thanks
>> Michael
>
> you need to work out how X,Y gets turned into Z

No, [s]he needs to work out how "a rectangle" turns into X and Y.

V
-- 
I do not respond to top-posted replies, please don't ask

[toc] | [prev] | [next] | [standalone]


#12063

Fromahso <ahso47@yahoo.com>
Date2011-12-04 22:56 -0800
Message-ID<55672f9a-f147-48f8-9c0d-8ffe6d4e3c7f@n6g2000vbg.googlegroups.com>
In reply to#12055
Ok it's a little more complicated:
---
Probes the terrain.  Pass in the XYZ coordinate of the probe point...
Other fields are filled in if we hit terrain, and a probe result
 * is returned.
----
So i give that function x,y,z coordinates and if it hits terrain I get
a result. Now I see why i only get a few points to draw as it hits
around the viewer but loses ground contact in the mountains etc.
I want to get the z (ground contact) within a 128x128 square around my
position, for a heightmap. (color z in different colors)
Many thanks indeed as I'm stuck...
Regards Michael

[toc] | [prev] | [next] | [standalone]


#12068

FromWerner <werasm@gmail.com>
Date2011-12-05 02:13 -0800
Message-ID<f99221d1-921e-4274-a624-e1c5a645912b@c13g2000vbh.googlegroups.com>
In reply to#12063
On Dec 5, 8:56 am, ahso <ahs...@yahoo.com> wrote:


> Many thanks indeed as I'm stuck...
> Regards Michael

Post some code...

[toc] | [prev] | [next] | [standalone]


#12074

Fromahso <ahso47@yahoo.com>
Date2011-12-05 06:19 -0800
Message-ID<31ef277e-863c-42fa-82b8-3e2b238d3866@t16g2000vba.googlegroups.com>
In reply to#12068
Getting closer, now I have lines from top left to bottom right:

	for( int x=0; x< 16384; x++ ){
draw x,y,z

I need also a y for loop?
Thanks
Michael

[toc] | [prev] | [next] | [standalone]


#12078

FromVictor Bazarov <v.bazarov@comcast.invalid>
Date2011-12-05 11:59 -0500
Message-ID<jbit92$gu9$1@dont-email.me>
In reply to#12074
On 12/5/2011 9:19 AM, ahso wrote:
> Getting closer, now I have lines from top left to bottom right:
>
> 	for( int x=0; x<  16384; x++ ){
> draw x,y,z
>
> I need also a y for loop?
> Thanks
> Michael

Michael,

You need to sit down and write your algorithm with a pencil on a piece 
of paper.  "I have lines from top left to bottom right" - what does that 
mean?  We have no idea.  It's not a description of an algorithm. 
Perhaps you need to think about the algorithm for a while.  Perhaps you 
should also look into some *formality* in your activities.  So far your 
posts indicate that your work is very hap-hazard.  Step back from 
programming for an hour and think what actions you would take if you 
were the computer and you needed to accomplish whatever goal you're 
setting for it.

To make tea, what do you need?  You need a cup, water source, dry tea 
(loose or in a bag) and a way to heat the water to the boiling point. 
Water source is in the kitchen (or the bathroom).  So, as part of the 
algorithm for making tea you need to ensure you're in one of those 
locations.  To boil water you need some energy source.  A microwave 
would do (make sure it's plugged into an electrical outlet).  And so on. 
  You write down preconditions, then you write down your actions.  It 
becomes the algorithm for accomplishing your goal.

Same thing with making calculations.  Or drawing a shape.  Or 
controlling a nuclear reactor.  You need the algorithm first, THEN you 
can put it in terms of the language you've chosen to implement it.

V
-- 
I do not respond to top-posted replies, please don't ask

[toc] | [prev] | [next] | [standalone]


#12087

Fromahso <ahso47@yahoo.com>
Date2011-12-05 23:07 -0800
Message-ID<3040eb13-e1b5-4955-a3a1-106e47eb6181@g7g2000vbd.googlegroups.com>
In reply to#12078
Look for yourself, your comments are all sick...

[toc] | [prev] | [next] | [standalone]


#12088

FromIan Collins <ian-news@hotmail.com>
Date2011-12-06 20:15 +1300
Message-ID<9k5tp2FuhiU1@mid.individual.net>
In reply to#12087
On 12/ 6/11 08:07 PM, ahso wrote:
> Look for yourself, your comments are all sick...

Who should look?  What comments?

Don't snip context.

-- 
Ian Collins

[toc] | [prev] | [next] | [standalone]


#12090

FromNick Keighley <nick_keighley_nospam@hotmail.com>
Date2011-12-06 01:37 -0800
Message-ID<901dbf42-ec9c-44e5-b40f-225e95aa9344@u6g2000vbg.googlegroups.com>
In reply to#12087
On Dec 6, 7:07 am, ahso <ahs...@yahoo.com> wrote:

> Look for yourself, your comments are all sick...

smart move. Ask for advice then criticise it...

you said

****
So i give that function x,y,z coordinates and if it hits terrain I
get
a result. Now I see why i only get a few points to draw as it hits
around the viewer but loses ground contact in the mountains etc.
I want to get the z (ground contact) within a 128x128 square around
my
position, for a heightmap. (color z in different colors)
Many thanks indeed as I'm stuck...
***

you really do nedd to sit down and think about the problem. What is a
"rectangle"? What is "terrain". What is a "result"?

also: viewer, ground contact, mountains, heightmap, color...

you add new terminology faster tahn you generate sensible requirements

to me this sounds like you might be taking a "slice" though the
terrain. In general this will yield a series of closed curves. And
then finding the point on one of these closed curves that is nearest
to your X,Y position. but I'm doing a *lot* of guessing.

[toc] | [prev] | [next] | [standalone]


#12092

Fromahso <ahso47@yahoo.com>
Date2011-12-06 05:02 -0800
Message-ID<1814981b-d0d5-4631-a8f9-9414001c4762@e2g2000vbb.googlegroups.com>
In reply to#12090
now I did a vector[x/y][rgb]
x or y and the color seems ok now how to draw this?

for( int laty=0; laty< Terrain_Size; laty++ ){
    for( int lonx=0; lonx< Terrain_Size; lonx++ ){
draw in opengl colored points
}
}
doesn't obviously work. how should those for loops look like?
Thanks

[toc] | [prev] | [next] | [standalone]


#12093

From"Fred Zwarts \(KVI\)" <F.Zwarts@KVI.nl>
Date2011-12-06 16:13 +0100
Message-ID<jblbeb$u52$1@news.albasani.net>
In reply to#12092
"ahso"  wrote in message 
news:1814981b-d0d5-4631-a8f9-9414001c4762@e2g2000vbb.googlegroups.com...
>
>now I did a vector[x/y][rgb]
>x or y and the color seems ok now how to draw this?
>
>for( int laty=0; laty< Terrain_Size; laty++ ){
>    for( int lonx=0; lonx< Terrain_Size; lonx++ ){
>draw in opengl colored points
>}
>}
>doesn't obviously work. how should those for loops look like?
>Thanks

I don't understand your "obviously". Can you explain why it doesn't work? 

[toc] | [prev] | [next] | [standalone]


#12094

FromVictor Bazarov <v.bazarov@comcast.invalid>
Date2011-12-06 10:24 -0500
Message-ID<jblc45$msf$1@dont-email.me>
In reply to#12092
On 12/6/2011 8:02 AM, ahso wrote:
> now I did a vector[x/y][rgb]
> x or y and the color seems ok now how to draw this?
>
> for( int laty=0; laty<  Terrain_Size; laty++ ){
>      for( int lonx=0; lonx<  Terrain_Size; lonx++ ){
> draw in opengl colored points
> }
> }
> doesn't obviously work.

"Obviously"?...  Well, yes, the

   draw in opengl colored points

is not C++ code (unless those are names of some macros that, when 
substituted, produce compilable C++ code).  Try replacing it with, say,

     printf("point: %d %d\n", laty, lonx);

and see if it "works" then.

 > how should those for loops look like?

The loops look OK, *given* certain assumptions.  But my assumptions can 
be totally different from yours.  State yours, and we can verify.

Also visit: http://catb.org/~esr/faqs/smart-questions.html and 
http://www.parashift.com/c++-faq-lite/how-to-post.html

V
-- 
I do not respond to top-posted replies, please don't ask

[toc] | [prev] | [next] | [standalone]


#12089

FromWerner <werasm@gmail.com>
Date2011-12-06 00:03 -0800
Message-ID<6b78f490-7e7c-4bac-b55c-7c05300fa3a4@w1g2000vba.googlegroups.com>
In reply to#12074
On Dec 5, 4:19 pm, ahso <ahs...@yahoo.com> wrote:
> Getting closer, now I have lines from top left to bottom right:
>
>         for( int x=0; x< 16384; x++ ){
> draw x,y,z
>
> I need also a y for loop?
> Thanks
> Michael

Michael,

What you have given us is not code... It
is not even psuedo code.

Function...

Output [Appropriate Name] (All necessary input parameters).

is already a start...

Kind regards,

Werner

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.c++


csiph-web