1 registered members (AndrewAMD),
1,248
guests, and 6
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
code question / connect points
#315328
03/14/10 19:25
03/14/10 19:25
|
Joined: Oct 2002
Posts: 8,939 planet.earth
ello
OP
Senior Expert
|
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:
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
MichaelGale
Serious User
|
Serious User
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: ello]
#315361
03/14/10 22:59
03/14/10 22:59
|
Joined: Jul 2002
Posts: 3,208 Germany
Error014
Expert
|
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]
#315365
03/14/10 23:15
03/14/10 23:15
|
Joined: Aug 2005
Posts: 1,230
MichaelGale
Serious User
|
Serious User
Joined: Aug 2005
Posts: 1,230
|
Hmm, I think Error014 is right. That should work.
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.
|
|
|
|