Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

Looking for a polygon tracer
Started by sporkfin Mar 02 2017 12:13 PM

- - - - -
4 replies to this topic
[TOPIC CONTROLS]
This topic has been archived. This means that you cannot reply to this topic.
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

sporkfin

[GLOBAL: userInfoPane.html]
sporkfin
  • Contributor

  • 500 posts
  • Corona SDK

I need a polygon tracer.  Ideally, I want to draw something in my graphics program, drop it in some sort of tracer and get a list of vertices that outline the shape.  I would then apply a graphics fill.

 

Has anyone seen anything like this or come up with a creative way to harvest vertices?

 

*Physics editors return vertices but they are broken into sub-shapes to avoid covexity and concavity.



[TOPIC: post.html]
#2

StarCrunch

[GLOBAL: userInfoPane.html]
StarCrunch
  • Contributor

  • 814 posts
  • Corona SDK

What does "draw something" entail? Painting or laying down other objects? Either way, I think breaking things up into sub-shapes is almost inevitable.

 

It needs a bit of cleanup and docs, but I have a binding to this, which uses the painting approach (probably at the moment to be serviced by my Bytemap plugin). Getting all the details right on objects is quite an undertaking; maybe something like this would be worth binding.

 

If you use a mesh the sub-shapes might not be much of an issue. By the sounds of it you're leaning toward polygon objects, in which case a "creative way to harvest vertices" would be--assuming everything is nicely triangulated--to gather up all the edges, then throw out any that show up twice (meaning they straddle two interior polygons). This would leave you with all the boundary edges (n.b. possibly including interior ones, meaning your shape has holes).

 

At this point every vertex should lie on exactly two edges, so you could start at an arbitrary vertex and choose one of the edges that contains it. Then you join that to the next vertex, remove the edge from some list so it won't turn up again in your search, and find the other edge that new vertex was in. You do this until you've walked around your shape, building up the list of vertices as you go. (If you have vertices and edges left over, it means your shape comprised several "islands", in which case you'll need to iterate this and do multiple polygons.)

 

Did that make sense in words?  :P This would probably be easier to explain in pictures.



[TOPIC: post.html]
#3

sporkfin

[GLOBAL: userInfoPane.html]
sporkfin
  • Contributor

  • 500 posts
  • Corona SDK

Thanks StarCrunch.  The picture your last paragraph puts into my mind is a custom mesh approach, did I get it?

 

Speaking of meshes, I think I should look into resolving this with a mesh.  I also like the Little Grasshopper article you referenced above, how cool is that?!  It's a bit beyond what I can tackle now but I'm bookmarking it of the future.  Thanks again for the suggestions.



[TOPIC: post.html]
#4

SGS

[GLOBAL: userInfoPane.html]
SGS
  • Corona Geek

  • 2,111 posts
  • Corona SDK

Surely you could whip up a simple Lua program to allow you to swipe a shape (or trace a png) and have that output vertices based on the x,y tap points?

 

A simple bit of maths could approximate the centre point and generate the code needed to turn that into a polygon.  Use maxX - minX / 2 and maxY - minY / 2 of your tap points to find the origin and map accordingly?

 

Could be useful to share for others?



[TOPIC: post.html]
#5

sporkfin

[GLOBAL: userInfoPane.html]
sporkfin
  • Contributor

  • 500 posts
  • Corona SDK

That's a good idea.  I've been playing around with a similar approach where each of the tap points can be moved to adjust the x/y position after placement.  

 

The trouble is that the shapes I'm working with are quite complex and would take several hundred, maybe over a thousand taps each.  Hmmm. . . if I build it I could pay my kids and their friend to do the tapping ; )

 

I'll let you know if I come up with anything useful.




[topic_controls]
[/topic_controls]