Gamestudio Links
Zorro Links
Newest Posts
Trading Journey
by M_D. 04/26/24 20:22
Help with plotting multiple ZigZag
by M_D. 04/26/24 20:03
Data from CSV not parsed correctly
by jcl. 04/26/24 11:18
M1 Oversampling
by jcl. 04/26/24 11:12
Why Zorro supports up to 72 cores?
by jcl. 04/26/24 11:09
Eigenwerbung
by jcl. 04/26/24 11:08
MT5 bridge not working on MT5 v. 5 build 4160
by EternallyCurious. 04/25/24 20:49
Zorro FIX plugin - Experimental
by flink. 04/21/24 07:12
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
4 registered members (M_D, AndrewAMD, Quad, Ayumi), 806 guests, and 5 spiders.
Key: Admin, Global Mod, Mod
Newest Members
wandaluciaia, Mega_Rod, EternallyCurious, howardR, 11honza11
19049 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
code question / connect points #315328
03/14/10 19:25
03/14/10 19:25
Joined: Oct 2002
Posts: 8,939
planet.earth
ello Offline OP
Senior Expert
ello  Offline OP
Senior Expert

Joined: Oct 2002
Posts: 8,939
planet.earth
Hi, I have a small issue trying to connect all points of a mesh with lines.

i have a code like:
Code:
for (i=0;i<pointnumber;i++)
{
 for (j=0;j<pointnumber;j++)
 {
  if (i!=j) line(point[i],point[j]);
 }
}



mainly my question is how can i prevent that when there already was for example a line from point[2] to point[5] another line points from point[5] to point[2]

thanks and cheers,
ello

Re: code question / connect points [Re: ello] #315330
03/14/10 19:33
03/14/10 19:33
Joined: Aug 2005
Posts: 1,230
M
MichaelGale Offline
Serious User
MichaelGale  Offline
Serious User
M

Joined: Aug 2005
Posts: 1,230
The simplest way to do that is probably to create a list of all lines you need to draw and then iterate through them (or mark them as drawn using a boolean once you have drawn them but that isn't really necessary here). This shouldn't be much of an issue if your points don't or rarely change as you can maintain the list structure in memory.

Also, if you are simply drawing straight lines then there isn't much of point in trying to avoid drawing the same line twice because it will most likely be slower to prevent that from happening than it would be to draw them twice.


Your friendly mod is at your service.
Re: code question / connect points [Re: MichaelGale] #315336
03/14/10 20:06
03/14/10 20:06
Joined: Oct 2002
Posts: 8,939
planet.earth
ello Offline OP
Senior Expert
ello  Offline OP
Senior Expert

Joined: Oct 2002
Posts: 8,939
planet.earth
those lines are planned to be 3d line objects so i think it matters to avoid doubles.. i guess i'll give the idea with that boolean a try ,thanks

Re: code question / connect points [Re: ello] #315361
03/14/10 22:59
03/14/10 22:59
Joined: Jul 2002
Posts: 3,208
Germany
Error014 Offline
Expert
Error014  Offline
Expert

Joined: Jul 2002
Posts: 3,208
Germany
why not start the second for-loop with j=i (or better yet i+1)?

... I mean, the first cycle connects point 1 with everything else. The second point thus only needs to be connected to all points after the first. (since 1->2 already exists). So in other words, since for the n-th point, the connections to all points lower than n already exist, you only need to connect it with all the others.

but then, its late. so i'm probably wrong.


Perhaps this post will get me points for originality at least.

Check out Dungeon Deities! It's amazing and will make you happy, successful and almost certainly more attractive! It might be true!
Re: code question / connect points [Re: Error014] #315363
03/14/10 23:08
03/14/10 23:08
Joined: Mar 2006
Posts: 2,252
Hummel Offline
Expert
Hummel  Offline
Expert

Joined: Mar 2006
Posts: 2,252
you should use Error014īs solution since itīs faster then indexing all points and itīs probably the fastest way anyway wink

Re: code question / connect points [Re: Error014] #315365
03/14/10 23:15
03/14/10 23:15
Joined: Aug 2005
Posts: 1,230
M
MichaelGale Offline
Serious User
MichaelGale  Offline
Serious User
M

Joined: Aug 2005
Posts: 1,230
Hmm, I think Error014 is right. That should work.

Code:
for (i=0;i<pointnumber-1;i++) // we don't need the last one
{
 for (j=i+1;j<pointnumber;j++) 
 {
  if (i!=j) line(point[i],point[j]);
 }
}



I think the best way to imagine this is by thinking of a circle of points.


Your friendly mod is at your service.
Re: code question / connect points [Re: MichaelGale] #315388
03/15/10 06:08
03/15/10 06:08
Joined: Oct 2002
Posts: 8,939
planet.earth
ello Offline OP
Senior Expert
ello  Offline OP
Senior Expert

Joined: Oct 2002
Posts: 8,939
planet.earth
thank you all.. that helped a lot grin


Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1