Got Questions? Get Answers.
Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
count number of triangles in a diagram

Subject: count number of triangles in a diagram

From: Faisal Ahmed

Date: 5 Aug, 2010 08:50:10

Message: 1 of 9

I have some co-ordinates and I have drawn a network with lines using "line" function. so there are some lines, some triangles, some quadrilaterals etc. is there any way in MATLAB that can automatically tell me only how many triangles are there and what are their vertices? tha'd be a life saver. thank you.

Subject: count number of triangles in a diagram

From: us

Date: 5 Aug, 2010 08:58:24

Message: 2 of 9

"Faisal Ahmed" <fap87@yahoo.com> wrote in message <i3du01$maa$1@fred.mathworks.com>...
> I have some co-ordinates and I have drawn a network with lines using "line" function. so there are some lines, some triangles, some quadrilaterals etc. is there any way in MATLAB that can automatically tell me only how many triangles are there and what are their vertices? tha'd be a life saver. thank you.

show CSSM a small example written in ML language...

us

Subject: count number of triangles in a diagram

From: Walter Roberson

Date: 5 Aug, 2010 14:59:53

Message: 3 of 9

Faisal Ahmed wrote:
> I have some co-ordinates and I have drawn a network with lines using
> "line" function. so there are some lines, some triangles, some
> quadrilaterals etc. is there any way in MATLAB that can automatically
> tell me only how many triangles are there and what are their vertices?
> tha'd be a life saver. thank you.

No there isn't.

Question: suppose the network of intersecting lines is such that I have
a theoretical quadrilateral but one side of it is sufficiently small
that the rendered version of it has two of the vertices at the same
pixel, thus making it _appear_ to be a triangle. Which should it be
counted as, triangle or quad?

Subject: count number of triangles in a diagram

From: ImageAnalyst

Date: 5 Aug, 2010 18:07:04

Message: 4 of 9

It's kind of kludgy but it might work. What if he saved the diagram
as an image, then did a hole fill (to get solid triangles), then did
bwlabel and regionprops to get info on the objects, and filtered them
based on their shape to get just the triangular objects?

Subject: count number of triangles in a diagram

From: Doug Hull

Date: 5 Aug, 2010 18:24:04

Message: 5 of 9

Post an example with an annotated version showing what you consider the correct answer.

Imagine an equilateral triangle with a line bisecting it through one vertex. Is that two triangles, or three counting the big one?

Imagine same equilateral triangle with a line bisecting in through one vertex and another line at another vertex bisecting also. These lines cross in the middle. How many here? Eight?

Doug

Subject: count number of triangles in a diagram

From: Walter Roberson

Date: 5 Aug, 2010 18:48:59

Message: 6 of 9

ImageAnalyst wrote:
> It's kind of kludgy but it might work. What if he saved the diagram
> as an image, then did a hole fill (to get solid triangles), then did
> bwlabel and regionprops to get info on the objects, and filtered them
> based on their shape to get just the triangular objects?

Can you hole-fill by shape? If not, then if the diagram is a web of lines, it
sounds as if hole filling would fill in all of the holes, leaving no way for
bwlabel to distinguish the sections ?

Instead of hole-filling, perhaps just negate the image, leaving 1's in the
holes and 0's for the lines, and then bwlabel and regionprops _that_ ?

Assuming, of course, that the resolution of the image is "good enough" that
there are no "accidental" intersections or non-intersections that are
important. Which seems to me to be a non-trivial problem if this is indeed a
diagram of intersecting line segments rather than a diagram of vertices and
non-intersecting connecting edges.

Subject: count number of triangles in a diagram

From: Doug Hull

Date: 5 Aug, 2010 19:04:05

Message: 7 of 9

If you only want the smallest triangles. Would a voronoi diagram help? Number of meet points that are not connected to any other meet points would be triangles.

Subject: count number of triangles in a diagram

From: Roger Stafford

Date: 5 Aug, 2010 19:07:20

Message: 8 of 9

"Faisal Ahmed" <fap87@yahoo.com> wrote in message <i3du01$maa$1@fred.mathworks.com>...
> I have some co-ordinates and I have drawn a network with lines using "line" function. so there are some lines, some triangles, some quadrilaterals etc. is there any way in MATLAB that can automatically tell me only how many triangles are there and what are their vertices? tha'd be a life saver. thank you.
- - - - - - - - - -
  I won't give a solution but rather some ideas. You haven't ruled out counting triangles that overlap. If that is the way you want it, for every pair of line segments determine whether they intersect and if so the point of their intersection. There is a simple algorithm to do that. Next for each line segment count the number of pairs of such intersection points along its length. For each such pair, that's a triangle somewhere. When you have added up all these counts, then divide by three because each triangle has been counted three times. That's very easy code to write.

  Of course all this assumes that no three line segments intersect at a common point. For that you would have to lay down some more specific rules of counting.

Roger Stafford

Subject: count number of triangles in a diagram

From: Roger Stafford

Date: 5 Aug, 2010 20:34:04

Message: 9 of 9

"Roger Stafford" <ellieandrogerxyzzy@mindspring.com.invalid> wrote in message <i3f258$a98$1@fred.mathworks.com>...
> "Faisal Ahmed" <fap87@yahoo.com> wrote in message <i3du01$maa$1@fred.mathworks.com>...
> > I have some co-ordinates and I have drawn a network with lines using "line" function. so there are some lines, some triangles, some quadrilaterals etc. is there any way in MATLAB that can automatically tell me only how many triangles are there and what are their vertices? tha'd be a life saver. thank you.
> - - - - - - - - - -
> I won't give a solution but rather some ideas. You haven't ruled out counting triangles that overlap. If that is the way you want it, for every pair of line segments determine whether they intersect and if so the point of their intersection. There is a simple algorithm to do that. Next for each line segment count the number of pairs of such intersection points along its length. For each such pair, that's a triangle somewhere. When you have added up all these counts, then divide by three because each triangle has been counted three times. That's very easy code to write.
>
> Of course all this assumes that no three line segments intersect at a common point. For that you would have to lay down some more specific rules of counting.
>
> Roger Stafford
- - - - - - - - -
  It has just occurred to me that I misstated things in that advice I gave. Where I said, "Next for each line segment count the number of pairs of such intersection points along its length. For each such pair, that's a triangle somewhere" I should have said the following instead.

  "Next, for each line segment and for each pair of such intersection points along its length determine whether the associated line segments themselves intersect (as you have actually already done.) If and when they do that forms a triangle somewhere."

Roger Stafford

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us