Gamestudio Links
Zorro Links
Newest Posts
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
Trading Journey
by howardR. 04/24/24 20:04
Zorro FIX plugin - Experimental
by flink. 04/21/24 07:12
Scripts not found
by juergen_wue. 04/20/24 18:51
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
3 registered members (wandaluciaia, AndrewAMD, 1 invisible), 765 guests, and 6 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
Find triangles in a graph #464033
01/15/17 20:45
01/15/17 20:45
Joined: Mar 2006
Posts: 1,993
Karlsruhe
PadMalcom Offline OP
Serious User
PadMalcom  Offline OP
Serious User

Joined: Mar 2006
Posts: 1,993
Karlsruhe
Hi, here is a little brain teaser:

I have a graph consisting of lines and looking exactly like a mesh - so the lines are arranged as if they were connected as triangles. Now I want to find all triangles in that graph and create vertices and indices out of them.

How can I do it?

Re: Find triangles in a graph [Re: PadMalcom] #464041
01/16/17 16:29
01/16/17 16:29
Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
Superku Offline
Senior Expert
Superku  Offline
Senior Expert

Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
I don't know what's the data structure for the graph like but I guess you should be able to iterate over all nodes and their direct neighbors easily, right? If so, then I think the following should work:

1) Iterate over all nodes.
2) For each node A, iterate over its neighbors B_0,1,2,..
3) For each neighbor B_i, iterate over its neighbors C_0,1,2,...
4) If C_j != A and C_j != B_i and there exists k with C_j == B_k, then there's a cycle of length 3 (or is that 2? not sure about definitions).
5) Either add 3 entries with the nodes' indices to a list or one entry with 3 values. Count the number of triangles.
6) Allocate mesh with #nodes and #triangles and setup the index buffer with the entries from the list.


"Falls das Resultat nicht einfach nur dermassen gut aussieht, sollten Sie nochmal von vorn anfangen..." - Manual

Check out my new game: Pogostuck: Rage With Your Friends

Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

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