tag:support.nodebox.net,2012-11-01:/discussions/show-your-work/101-texturizer-nodeNodeBox: Discussion 2015-04-02T23:51:25Ztag:support.nodebox.net,2012-11-01:Comment/364588532015-04-01T07:40:22Z2015-04-01T07:40:25ZTexturizer Node<div><p>One thing I was wondering:</p>
<p>Before I found the Delete node, I was thinking to try to
implement this algorithm for seeing if a point on the background
grid fell within the bounds of the polygon:</p>
<p><a href="http://en.wikipedia.org/wiki/Point_in_polygon">http://en.wikipedia.org/wiki/Point_in_polygon</a></p>
<p>However I could not think how to do it in Nodebox. It would be
simple enough to take a point on the grid, get its y value, and
then draw and line from x = -500 to y = 500, maintaining that same
value of y, but how to find out where that line intersects the
polygon? Anyone have any leads on that?</p></div>Rorytag:support.nodebox.net,2012-11-01:Comment/364588532015-04-02T11:24:45Z2015-04-02T11:24:45ZTexturizer Node<div><p>You can recover a list of all the inflection points in a polygon
by attaching a lookup node, setting the key to "points", and
changing the output range of the lookup node from "value" to "list"
(via "settings" in the metadata dialog).</p>
<p>Once you have this you can take each pair of adjacent points in
turn and reconstruct each line segment of the polygon (remembering
that the last point is adjacent to the first). One way of
determining whether each segment intersects with your ray from
outside is to calculate the slope of the ray r and the line s
extending through the segment, put the equation for each line in
slope intercept form, and use basic algebra to solve for
intersection, that is, solve for r(x) = s(x). (You can make that
even easier by choosing a horizontal line for the ray so that
r(x)=0.) Unless the two lines are parallel they will intersect
somewhere. Once you have that point it's a simple matter to see
whether the intersection occurs within the bounds of the original
segment, and before the endpoint of the ray. (There is probably an
easier way but this is the first thing that came to mind.)</p>
<p>The final outcome will be 0 if false (no intersection within
segment bounds) or 1 if true.<br>
Now just repeat for each segment and take the sum of the outcomes.
If this number is odd, the point is inside, if even outside.</p>
<p>That's one approach. Perhaps someone else can suggest a simpler
method.</p>
<p>John</p></div>johntag:support.nodebox.net,2012-11-01:Comment/364588532015-04-02T11:46:47Z2015-04-02T11:46:47ZTexturizer Node<div><p>Incidentally, you can get a cleaner texture fill using the
compound node. Create a grid of dots bigger than the shape and
adjust dot size and density to your taste. Then hook the shape and
the grid of dots to the compound node (set to intersection).</p>
<p>This will give you the interior. To create a nice edge, attach a
colorize node to the shape, set its fill to white and its edge
width > 0, and feed the colorize node and the compound node (in
that order) into a combine node.</p>
<p>NodeBox file and screenshot attached.</p>
<p>For other textures you could make a grid of white touching
rectangles to form a cross-hatch pattern, rotate that 45 degrees
for another variation, and so on.</p>
<p>This is a fun idea. Now I want to make some old-school textures
for my shapes!</p>
<p>John</p></div>johntag:support.nodebox.net,2012-11-01:Comment/364588532015-04-02T12:03:20Z2015-04-02T12:03:21ZTexturizer Node<div><p>John, thats very cool!</p>
<p>That was exactly the approach I tried to take first, but I
neglected to connect the polygon both to the compound and
separately to the combine node. So much simpler. Thanks.....</p>
<p>I think a NodeBox challenge would be a super useful way to learn
(for me!). This week texture, next week ???</p></div>Rorytag:support.nodebox.net,2012-11-01:Comment/364588532015-04-02T12:36:47Z2015-04-02T12:36:48ZTexturizer Node<div><p>Thanks!</p></div>Rorytag:support.nodebox.net,2012-11-01:Comment/364588532015-04-02T23:51:25Z2015-04-02T23:51:25ZTexturizer Node<div><p>:)</p></div>john