Convex filled polygons

Until our dedicated user library is in place you can post examples and modules here

Moderators: electrogear, exonerate

Convex filled polygons

Postby mwvdlee on Sun Jul 04, 2010 8:40 am

Here's a really, really slow example of how to draw filled convex polygons using S|M.

ConvexPoly.osm
(2.81 KiB) Downloaded 219 times

It uses a horizontal scanline method; draw the outline using standard primitives, find first and last pixel in a row, draw all pixels inbetween.
Should be stable, albeit slow, for any convex polygon. I'm pretty sure there's room for performance improvement, so please go ahead and try ;)
Make sure you only use convex (or understand the algorithm) polygons that fit inside (or understand the algorithm) the margins of the view.
My current top SynthMaker bug:
    1. MIDI Input issue (showstopper, no workaround)
    2. All my previous bugs in SM1.7, because bug 1 makes SM2 worse than SM1.7
User avatar
mwvdlee
smanatic
 
Posts: 552
Joined: Thu Dec 03, 2009 8:42 am
Location: NL

Re: Convex filled polygons

Postby MegaHurtz on Sun Jul 04, 2010 12:44 pm

cool. :love:

Je onderschrift is ook errug inspirerend, mss van de winter wat bèèta`s.
User avatar
MegaHurtz
smaniac
 
Posts: 1522
Joined: Mon Aug 11, 2008 5:29 pm
Location: Eindhoven/Netherlands

Re: Convex filled polygons

Postby trogluddite on Sun Jul 04, 2010 1:11 pm

Nice work.
Taking inspiration from your nested draw loops, here's one for drawing a regular polygon with any number of sides...
Regular Polygon.osm
(57.4 KiB) Downloaded 209 times
Feel free to use any schematics and algorithms I post on the forum in your own designs - a credit is appreciated (but not a requirement).
Don't stagnate, mutate to create. Without randomness and serendipity the earth would be just another barren rock.
User avatar
trogluddite
smychopath
 
Posts: 3028
Joined: Mon Oct 20, 2008 3:52 pm
Location: Yorkshire, UK

Re: Convex filled polygons

Postby MegaHurtz on Sun Jul 04, 2010 2:29 pm

wow :love:
Me like hexagons :D
Into the toolkit they go.. pom pom
User avatar
MegaHurtz
smaniac
 
Posts: 1522
Joined: Mon Aug 11, 2008 5:29 pm
Location: Eindhoven/Netherlands

Re: Convex filled polygons

Postby mwvdlee on Sun Jul 04, 2010 2:58 pm

trogluddite wrote:Nice work.
Taking inspiration from your nested draw loops, here's one for drawing a regular polygon with any number of sides...
Regular Polygon.osm

Nice!
I like "cheating" like this :)
It's a bit faster without visual difference if you disable AA for the "fill", increase the inner loops' step size and decrease the pen thickness multiplier. I tried step 2 pixels with 1.5x and can see no artifacts.
I guess you could draw any irregular convex polygon like this too, if you could determine a point inside the shape.In the case of S|M it'd probably be faster than my scanline version. Come to think of it, in a convex polygon you could take any of the given vertices as the center and skip the lines connected to the vertice. An interresting idea.
My current top SynthMaker bug:
    1. MIDI Input issue (showstopper, no workaround)
    2. All my previous bugs in SM1.7, because bug 1 makes SM2 worse than SM1.7
User avatar
mwvdlee
smanatic
 
Posts: 552
Joined: Thu Dec 03, 2009 8:42 am
Location: NL

Re: Convex filled polygons

Postby Jay on Sun Jul 04, 2010 3:27 pm

Great demonstration mwvdlee! thanks!
and
I really love that one Trogg, got me so exited i nearly coughed my good lung up! :D i have been trying to do shapes for ages but i am to thick for the maths to get anywhere ;)

very cool guys

Best Regards
The history of science shows that theories are perishable.With every new truth that is revealed,we get a better understanding of Nature and our conceptions and views are modified. - Nikola Tesla.
http://www.energeticforum.com/renewable-energy/
Jay
essemilian
 
Posts: 469
Joined: Mon Sep 22, 2008 7:20 pm
Location: Scotland.UK

Re: Convex filled polygons

Postby mwvdlee on Sun Jul 04, 2010 5:33 pm

Based on trogludite's line trick; a new, much faster irregular convex filled polygon renderrer.
Actually, it's a triangle renderer in a loop.
ConvexPoly 0002.osm
(3.86 KiB) Downloaded 197 times

There IS an issue, which seem to stem from timing issues. The coordinates can get mangled when rendering multiple triangles and when the view is big. You could fix if by increasing the step size and/or line-width, but it seems there is just a physical limit to the number of iterations you can do with a draw loop.

This is "proof-of-concept"; I'm sure trogludite or others will quickly improve upon it.

The only benefit my original scanline version had, is that you're not restricted to straight edges of the shape; if you set the curve to TRUE in the point array module, you'd get a filled curvy polygon. But curves have the slight risk of becoming concave.
My current top SynthMaker bug:
    1. MIDI Input issue (showstopper, no workaround)
    2. All my previous bugs in SM1.7, because bug 1 makes SM2 worse than SM1.7
User avatar
mwvdlee
smanatic
 
Posts: 552
Joined: Thu Dec 03, 2009 8:42 am
Location: NL

Re: Convex filled polygons

Postby MichaelBenjamin on Sun Jul 04, 2010 5:43 pm

pretty cool, i like these shapes.
do you think something like this is possible?
Image
User avatar
MichaelBenjamin
smaniac
 
Posts: 1439
Joined: Thu Jul 12, 2007 3:26 pm

Re: Convex filled polygons

Postby mwvdlee on Sun Jul 04, 2010 6:10 pm

MichaelBenjamin wrote:pretty cool, i like these shapes.
do you think something like this is possible?
Image

Short answer: Yes.
Long answer; these shapes are irregular, Trog's version specializes in regular polygons only, so you'd have to use either of my versions. None of the versions can handle transparency by itself, but you could render to a bitmap, the scan the bitmap's pixels and do the transparency yourself. Also remember to calculate rotation for all vertices and sort them along the Z axis. It'll work, but not usably fast. Also, that animation is lighted, which you'd have to calculate too. S|M has all the facilities to do all of this, but it will be sheer masochism to even try.

Using solid surfaces makes it a lot easier:
- Calculate all the triangles (store x/y/z triads in an array).
- Cull back faces (integrate with previous step and only store front faces).
- Calculate lighting (if you can recognize back faces, you've already done most of the work for this).
- Render all triangles in a loop.

It may be a lot easier with solid surfaces, but I'm sure as hell not going to try doing it in S|M ;)
My current top SynthMaker bug:
    1. MIDI Input issue (showstopper, no workaround)
    2. All my previous bugs in SM1.7, because bug 1 makes SM2 worse than SM1.7
User avatar
mwvdlee
smanatic
 
Posts: 552
Joined: Thu Dec 03, 2009 8:42 am
Location: NL

Re: Convex filled polygons

Postby MichaelBenjamin on Sun Jul 04, 2010 6:43 pm

can you recommend an easy to use 3d program that can draw, texture, light and animate a simple shape like that?
User avatar
MichaelBenjamin
smaniac
 
Posts: 1439
Joined: Thu Jul 12, 2007 3:26 pm

Re: Convex filled polygons

Postby Nu Audio Science on Sun Jul 04, 2010 8:45 pm

Blender is about your best bet MB
There are a hell of a lot of tutorials to learn from and it's free

Myself i use Silo and Lightwave but they would be over the top for something like this

But anyway try HERE

That place has the links to pretty much every app made

NAS
Oh blimey
User avatar
Nu Audio Science
smunatic
 
Posts: 2236
Joined: Thu May 05, 2005 12:29 am

Re: Convex filled polygons

Postby Acrobat on Wed Jul 28, 2010 3:25 pm

mwvdlee wrote:Here's ....

...one of the coolest things seen in the graphic department this year! Thanks mwvdlee and Trog for the regular mods! :D
User avatar
Acrobat
smaniac
 
Posts: 1660
Joined: Mon Jun 04, 2007 10:50 pm
Location: Roma, Italia

Re: Convex filled polygons

Postby philter5 on Wed Jul 28, 2010 3:56 pm

Acrobat wrote:
mwvdlee wrote:Here's ....

...one of the coolest things seen in the graphic department this year! Thanks mwvdlee and Trog for the regular mods! :D


Ohh Yeeeeees thx to our graphic-specialists :love:
---Yes, a piece of software CAN be your best friend---
User avatar
philter5
smaniac
 
Posts: 1480
Joined: Thu Jan 04, 2007 7:52 pm
Location: Germany

Re: Convex filled polygons

Postby mwvdlee on Sat Aug 14, 2010 6:16 pm

Based on this: viewtopic.php?f=10&t=9706&st=0&sk=t&sd=a&start=60#p71269

Here's another regular polygon renderer. It should be a lot faster (and spare a lot of the limited loop draws). Only drawback is that it only works for 4 sides or more. Preferably 5 or more, because you could make a much more efficient renderer for 4 sides without loop. For convenience, I included the optimized one for 4 sides (a.k.a. squares) too :P; it requires no loop and can use transparent colors.

RegularPolies.osm
(17.34 KiB) Downloaded 179 times
My current top SynthMaker bug:
    1. MIDI Input issue (showstopper, no workaround)
    2. All my previous bugs in SM1.7, because bug 1 makes SM2 worse than SM1.7
User avatar
mwvdlee
smanatic
 
Posts: 552
Joined: Thu Dec 03, 2009 8:42 am
Location: NL

Re: Convex filled polygons

Postby aliasant on Sat Aug 14, 2010 7:04 pm

mwvdlee wrote:Based on this: viewtopic.php?f=10&t=9706&st=0&sk=t&sd=a&start=60#p71269

Here's another regular polygon renderer. It should be a lot faster (and spare a lot of the limited loop draws). Only drawback is that it only works for 4 sides or more. Preferably 5 or more, because you could make a much more efficient renderer for 4 sides without loop. For convenience, I included the optimized one for 4 sides (a.k.a. squares) too :P; it requires no loop and can use transparent colors.

RegularPolies.osm


That IS COOL.
Making knobs maybe :)
It's never to late to be late.....
http://martinrodensjo.smugmug.com/
User avatar
aliasant
smunatic
 
Posts: 2386
Joined: Sat Dec 30, 2006 5:49 pm
Location: Sweden

Next

Return to Examples

Who is online

Users browsing this forum: No registered users and 3 guests