<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">2014-11-08 11:53 GMT+01:00 Barend Gehrels [via Boost] <span dir="ltr">&lt;<a href="/user/SendEmail.jtp?type=node&node=4669040&i=0" target="_top" rel="nofollow" link="external">[hidden email]</a>&gt;</span>:<br><blockquote style='border-left:2px solid #CCCCCC;padding:0 1em' class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

	
  
    
  
  
    <div>Gu Grzegorz,<br>
      <br>
      gchlebus wrote On 8-11-2014 2:33:<br>
    </div>
    <blockquote style='border-left:2px solid #CCCCCC;padding:0 1em' style="border-left:2px solid #cccccc;padding:0 1em" type="cite">
      <div dir="ltr">
        <div class="gmail_extra"><br>
          <div class="gmail_quote">2014-11-07 19:30 GMT+01:00 Barend
            Gehrels [via Boost] <span dir="ltr">&lt;<a href="http://user/SendEmail.jtp?type=node&amp;node=4668825&amp;i=0" rel="nofollow" link="external" target="_blank">[hidden
                email]</a>&gt;</span>:<div><div class="h5"><br>
            <blockquote style='border-left:2px solid #CCCCCC;padding:0 1em' style="border-left:2px solid #cccccc;padding:0 1em" class="gmail_quote">
              <div>Hi Grzegorz,<br>
                <br>
                gchlebus wrote On 6-11-2014 19:08:<br>
              </div>
              <blockquote style='border-left:2px solid #CCCCCC;padding:0 1em' style="border-left:2px solid #cccccc;padding:0 1em" type="cite">
                <div dir="ltr"><br>
                  <div class="gmail_extra"><br>
                    <div class="gmail_quote">2014-11-04 17:23 GMT+01:00
                      Barend Gehrels [via Boost] <span dir="ltr">&lt;<a href="http://user/SendEmail.jtp?type=node&amp;node=4668774&amp;i=0" rel="nofollow" link="external" target="_blank">[hidden

                          email]</a>&gt;</span>:
                      <div>
                        <div><br>
                          <blockquote style='border-left:2px solid #CCCCCC;padding:0 1em' style="border-left:2px solid #cccccc;padding:0 1em" class="gmail_quote">
                            <div>Hi Grzegorz,<br>
                              <br>
                              <br>
                            </div>
                            <blockquote style='border-left:2px solid #CCCCCC;padding:0 1em' style="border-left:2px solid #cccccc;padding:0 1em" type="cite">
                              <div class="gmail_extra"><br>
                                <div class="gmail_quote">2014-10-29
                                  23:18 GMT+01:00 Barend Gehrels [via
                                  Boost] <span dir="ltr">&lt;<a href="http://user/SendEmail.jtp?type=node&amp;node=4668617&amp;i=0" rel="nofollow" link="external" target="_blank">[hidden email]</a>&gt;</span>:<span><br>
                                    <blockquote style='border-left:2px solid #CCCCCC;padding:0 1em' style="border-left:2px solid #cccccc;padding:0 1em" class="gmail_quote"> <br>
                                      <span><br>
                                        gchlebus wrote On 24-10-2014
                                        16:44: </span>
                                      <div>
                                        <div><span><br>
                                            &gt; Hi, <br>
                                            &gt; <br>
                                            &gt; I am wondering whether
                                            it would be possible to
                                            achieve anisotropic
                                            buffering <br>
                                            &gt; (distances in neg x,
                                            pos x, neg y, pos y can have
                                            different values) of a <br>
                                            &gt; polygon using the
                                            buffer function with
                                            custom-implemented distance
                                            strategy. <br>
                                            &gt; What I want to achieve
                                            is presented on the figure
                                            2-b in the following <br>
                                            &gt; paper: <br>
                                            &gt; <a href="http://itcnt05.itc.nl/agile_old/Conference/mallorca2002/proceedings/posters/p_molina.pdf" rel="nofollow" link="external" target="_blank">http://itcnt05.itc.nl/agile_old/Conference/mallorca2002/proceedings/posters/p_molina.pdf</a><br>
                                            &gt; <br>
                                          </span>&gt; I would be
                                          grateful to hear from you
                                          whether it is doable, and if
                                          positive, <br>
                                          &gt; how one could implement
                                          such a custom distance
                                          strategy. </div>
                                      </div>
                                      The current distance strategy has
                                      (currently) no means to get the
                                      angle, <br>
                                      or a vector of the new point to be
                                      buffered. We can consider adding
                                      that. <br>
                                      <br>
                                      However, by writing custom
                                      strategies for join, side, point
                                      (for <br>
                                      point-buffers) and possibly end
                                      (for line-buffers) you should be
                                      able to <br>
                                      create this, because these have
                                      this information. <br>
                                      <br>
                                      Attached a program doing similar
                                      things with polygons and points (I
                                      vary <br>
                                      the distance based on angle - you
                                      will have to do something with
                                      your <br>
                                      anistropic model). <br>
                                      <br>
                                      The output is also attached. <br>
                                      <br>
                                      The program defines three custom
                                      strategies, all based on the same
                                      <br>
                                      mechanism, to create interesting
                                      output. <br>
                                      I did not do the end-strategy but
                                      that would look similar, you can
                                      look <br>
                                      at the provided end-strategy
                                      (round) and apply the same
                                      function. <br>
                                      <span></span></blockquote>
                                  </span></div>
                              </div>
                            </blockquote>
                            <br>
                            <br>
                            gchlebus wrote On 31-10-2014 18:13:<span><br>
                              <blockquote style='border-left:2px solid #CCCCCC;padding:0 1em' style="border-left:2px solid #cccccc;padding:0 1em" type="cite">
                                <div dir="ltr">I really appreciate your
                                  example code, it helped me a lot.
                                  Attached you can find my source code.
                                  <div>In my implementation of the
                                    anisotropic buffering I didn&#39;t know
                                    how to make use of the distance
                                    strategy, as it was possible to make
                                    it work using only side and join
                                    strategies.</div>
                                  <div>I encountered strange behavior
                                    when changing number of points
                                    describing a full circle. Using 360
                                    points produced a good output,
                                    whereas 90 points caused only the
                                    second polygon to be buffered (see
                                    attached figures). I would be
                                    thankful if you could help me to
                                    resolve this issue as well as for
                                    any remarks to my code.</div>
                                  <div><br>
                                  </div>
                                </div>
                              </blockquote>
                              <br>
                            </span> I could reproduce this. Basically
                            the join-strategy should always include
                            points perp1 and perp2 (these are the two
                            points perpendicular to the two sides which
                            the join-strategy joints). Either they are
                            re-calculated, or they can be just added to
                            begin and end. So I did the last option, and
                            that piece of code now looks like:<br>
                            <br>
                                  double const angle_increment = 2.0 *
                            M_PI / double(point_count);<br>
                                  double alpha = angle1 -
                            angle_increment;<br>
                            <b>      range_out.push_back(perp1);</b><b>
                              // added<br>
                            </b>      for (int i = 0; alpha &gt;= angle2
                            &amp;&amp; i &lt; point_count; i++, alpha -=
                            angle_increment)<br>
                                  {<br>
                                    pdd v = getPointOnEllipse(alpha);<br>
                                    Point p;<br>
                                    bg::set&lt;0&gt;(p,
                            bg::get&lt;0&gt;(vertex) + v.first);<br>
                                    bg::set&lt;1&gt;(p,
                            bg::get&lt;1&gt;(vertex) + v.second);<br>
                                    range_out.push_back(p);<br>
                                  }<br>
                            <b>      range_out.push_back(perp2);</b><b>
                              // added</b><br>
                            <br>
                            My sample code of course also suffered from
                            that, so I added it there too if I use it in
                            the future.<br>
                            <br>
                            I tested your algorithm with various points
                            and distances and it now seems always OK.<br>
                            <br>
                            You ask for remarks on your code: it looks
                            good ;-) one thing, many terms are
                            recalculated such as pow(xPos*tan(alpha),
                            2)); or just tan(alpha), I usually store
                            these into variables, to avoid expensive
                            recalculations of the same terms, though
                            maybe they are optimized by the compiler.<br>
                            <br>
                            Regards, Barend<br>
                            <br>
                            <br>
                            P.S. this list discourages top-postings<span><br>
                              <br>
                            </span></blockquote>
                          <div><br>
                          </div>
                          <div>Hallo Barend,</div>
                          <div><br>
                          </div>
                          <div>I corrected the join strategy, but still
                            the buffering doesn&#39;t work in all cases as
                            expected. When using xPos = 1, and other
                            values equal 0, the buffered polygon
                            contains a hole (see xPos1.svg), whereas
                            setting xPos to 2 produces a correct result
                            (xPos2.svg). Do you know how to fix it? I
                            attached also main.cpp, as I changed the
                            code a bit and it contains the polygon for
                            which causes the strange behavior.</div>
                          <div><br>
                          </div>
                        </div>
                      </div>
                    </div>
                  </div>
                </div>
              </blockquote>
              <br>
              <br>
              That is most probably caused by an error in some of your
              calculations:<br>
              <br>
              The line y = sqrt(yPos2 * (1 - pow(x, 2) / xNeg2));<br>
              causes a NAN for this input:<br>
              <br>
              alpha about PI<br>
              then xNeg2 = 0.010000000000000002<br>
              and x = -0.10000000000000002<br>
              and yPos2 = 0.010000000000000002<br>
              <br>
              This adds a weird line containing NAN to the join, causing
              the buffer process fail.<br>
              I got this using these parameters:<br>
              double xPos = 1.0, xNeg = 0.1, yPos = 0.1, yNeg = 0.1;<br>
              <br>
              and not the parameters you have (that was fine for me).<br>
              <br>
              I think you should make the calculations full-proof
              first...<br>
              <br>
              For example add a line in the join-strategy:<br>
                      std::cout &lt;&lt; i &lt;&lt; &quot; &quot;&lt;&lt; angle1
              &lt;&lt; &quot; &quot; &lt;&lt; angle2 &lt;&lt; &quot; &quot; &lt;&lt; v.first
              &lt;&lt; &quot; &quot; &lt;&lt; v.second &lt;&lt; std::endl;<br>
              <br>
              <br>
              Regards, Barend<span><br>
                <br>
              </span></blockquote>
            <div><br>
            </div>
            <div>Thanks, I&#39;ll try to improve my calculations. </div>
            <div>By the way, I was playing with different strategies
              combinations and I found out that when using only boost
              buffer strategies:</div>
            <div>
              <div>        </div>
              <div>        double points_per_circle = 36;</div>
              <div>        double distance = 130;</div>
              <div>       
                bg::strategy::buffer::distance_symmetric&lt;double&gt;
                distance_strategy(distance); </div>
              <div><span style="white-space:pre-wrap"> </span>bg::strategy::buffer::end_flat
                end_strategy; </div>
              <div><span style="white-space:pre-wrap"> </span>bg::strategy::buffer::point_circle
                point_strat(points_per_circle);</div>
              <div><span style="white-space:pre-wrap"> </span>bg::strategy::buffer::side_straight
                sideStrat;</div>
              <div><span style="white-space:pre-wrap"> </span>bg::strategy::buffer::join_round
                joinStrat(points_per_circle);</div>
            </div>
            <div><br>
            </div>
            <div>the buffer function can still fail (produce no output)
              when the distance is higher than 128 (e.g, 128, 130, 150,
              300, 400). But this happens up to a certain value, where
              the buffer function starts producing a correct output
              (e.g., distances 900, 1000). </div>
            <div><br>
            </div>
          </div></div></div>
        </div>
      </div>
    </blockquote>
    <br>
    Hmm, I see (starting at different values, but I can reproduce).<br>
    <br>
    I created a ticket, will be looked at. Thanks for reporting.<br>
    <a href="https://svn.boost.org/trac/boost/ticket/10770" rel="nofollow" link="external" target="_blank">https://svn.boost.org/trac/boost/ticket/10770</a><span class=""><br>
    <br>
    Barend<br>
    <br></span></blockquote><div><br></div><div>Hi Barend,</div><div><br></div><div>I&#39;m glad that I could help. </div><div>Anyway, I fixed the bug with NAN, but still when using (e.g. xNeg = 1, other 0) the buffer produces no output. I am really wondering, how it could work on your machine.</div><div>I printed the values used by join and side strategies and they seem to be fine (no NANs or other strange values) - see attached log.txt and updated main.cpp used to produce the log file.</div><div><br></div><div>I&#39;ve compiled my code using msvc 12.0 and gcc 4.8.</div><div><br></div><div><br></div><div>Best,</div><div>Grzegorz </div></div></div></div>
<!--start-attachments--><div class="small"><br/><img src="http://boost.2283326.n4.nabble.com/images/icon_attachment.gif" > <strong>log.txt</strong> (976 bytes) <a href="http://boost.2283326.n4.nabble.com/attachment/4669040/0/log.txt" target="_top" rel="nofollow" link="external">Download Attachment</a><br/><img src="http://boost.2283326.n4.nabble.com/images/icon_attachment.gif" > <strong>main.cpp</strong> (13K) <a href="http://boost.2283326.n4.nabble.com/attachment/4669040/1/main.cpp" target="_top" rel="nofollow" link="external">Download Attachment</a></div><!--end-attachments-->

	
	
	
<br/><hr align="left" width="300" />
View this message in context: <a href="http://boost.2283326.n4.nabble.com/boost-geometry-buffer-distance-strategies-tp4668469p4669040.html">Re: [boost.geometry] buffer distance strategies</a><br/>
Sent from the <a href="http://boost.2283326.n4.nabble.com/Boost-Users-f2553780.html">Boost - Users mailing list archive</a> at Nabble.com.<br/>