Hi Jo,<br><br>Thanks for your reply.<br><br>Ok, your last image seems to be no problem.<br><br>Regards,<br><br>Sanak.<br><br><div class="gmail_quote">2009/8/30 Jo <span dir="ltr">&lt;<a href="mailto:doublebyte@gmail.com">doublebyte@gmail.com</a>&gt;</span><br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">Thinking better, I could see what I was doing wrong.<br>
I was rotating a point around (0,0), rather than rotating it around my<br>
origin (the centroid). Therefore, I had to add the difference between<br>
the point and centroid coordinates to the sin and cosine terms:<br>
<br>
                double rx=centroid-&gt;getX()+cos(fangle)*(x-centroid-&gt;getX())-sin(fangle)*(y-centroid-&gt;getY());<br>
                double ry=centroid-&gt;getY()+sin(fangle)*(x-centroid-&gt;getX())+cos(fangle)*(y-centroid-&gt;getY());<br>
<br>
And calling consecutively this function, gives me the equally spaced<br>
radials from a centroid of a polygon to its external ring; in this<br>
example, using a 45 degrees angle:<br>
<br>
<a href="http://ladybug.no-ip.org/files/radials_calc.png" target="_blank">http://ladybug.no-ip.org/files/radials_calc.png</a><br>
<br>
                                   cheers,<br>
                                              Jo<br>
<br>
<br>
2009/8/29  &lt;<a href="mailto:geos-devel-request@lists.osgeo.org">geos-devel-request@lists.osgeo.org</a>&gt;:<br>
&gt; Send geos-devel mailing list submissions to<br>
<div class="im">&gt;        <a href="mailto:geos-devel@lists.osgeo.org">geos-devel@lists.osgeo.org</a><br>
&gt;<br>
</div>&gt; To subscribe or unsubscribe via the World Wide Web, visit<br>
<div class="im">&gt;        <a href="http://lists.osgeo.org/mailman/listinfo/geos-devel" target="_blank">http://lists.osgeo.org/mailman/listinfo/geos-devel</a><br>
</div>&gt; or, via email, send a message with subject or body &#39;help&#39; to<br>
&gt;        <a href="mailto:geos-devel-request@lists.osgeo.org">geos-devel-request@lists.osgeo.org</a><br>
&gt;<br>
&gt; You can reach the person managing the list at<br>
&gt;        <a href="mailto:geos-devel-owner@lists.osgeo.org">geos-devel-owner@lists.osgeo.org</a><br>
&gt;<br>
&gt; When replying, please edit your Subject line so it is more specific<br>
&gt; than &quot;Re: Contents of geos-devel digest...&quot;<br>
&gt;<br>
&gt;<br>
&gt; Today&#39;s Topics:<br>
&gt;<br>
&gt;   1. Re: Computing Radials inside a Polygon (Jo)<br>
&gt;<br>
&gt;<br>
&gt; ----------------------------------------------------------------------<br>
&gt;<br>
&gt; Message: 1<br>
&gt; Date: Sat, 29 Aug 2009 16:16:23 +0100<br>
&gt; From: Jo &lt;<a href="mailto:doublebyte@gmail.com">doublebyte@gmail.com</a>&gt;<br>
&gt; Subject: [geos-devel] Re: Computing Radials inside a Polygon<br>
&gt; To: <a href="mailto:geos-devel@lists.osgeo.org">geos-devel@lists.osgeo.org</a><br>
&gt; Message-ID:<br>
&gt;        &lt;<a href="mailto:23ab5f0a0908290816j66928c44y58de481b26525657@mail.gmail.com">23ab5f0a0908290816j66928c44y58de481b26525657@mail.gmail.com</a>&gt;<br>
&gt; Content-Type: text/plain; charset=ISO-8859-1<br>
<div><div></div><div class="h5">&gt;<br>
&gt; Hi Jo,<br>
&gt;<br>
&gt; I think that each rotate angles should be calculated more simply.<br>
&gt; (I think rotation matrix is valid when centroid is equal to origine(0, 0).)<br>
&gt;<br>
&gt; The following code is pseudo code. (Sorry I haven&#39;t OGR environment...)<br>
&gt;<br>
&gt; ===================================<br>
&gt; // get minCircle radius. (If radius is not calculated yet)<br>
&gt; double radius=Distance(&amp;centroid, &amp;startPt); // I don&#39;t know that Distance<br>
&gt; function is implemented in OGR...<br>
&gt; // get start angle.<br>
&gt; double startAngle=atan2(&amp;startPt.getY()-&amp;centroid.getY(),<br>
&gt; &amp;startPt.getX()-&amp;centroid.getX());<br>
&gt;<br>
&gt; for (size_t i=0; i &lt;n; ++i){<br>
&gt;       OGRLineString dLine;<br>
&gt;       dLine.addPoint(&amp;centroid);<br>
&gt;<br>
&gt;       double rx=centroid.getX() + radius*cos(startAngle+fangle*i);<br>
&gt;       double ry=centroid.getY() + radius*sin(startAngle+fangle*i);<br>
&gt;        :<br>
&gt; }<br>
&gt; ===================================<br>
&gt;<br>
&gt; Regards,<br>
&gt;<br>
&gt; Sanak.<br>
&gt;<br>
&gt; Hi Sanak,<br>
&gt; First of all, thanks for your reply!<br>
&gt; I think I didn&#39;t explain myself clearly though...<br>
&gt;<br>
&gt; The idea is to compute radials from the centroid of the polygon, to<br>
&gt; its external ring, at equal intervals. Something like this:<br>
&gt;<br>
&gt; <a href="http://ladybug.no-ip.org/files/radials_final.png" target="_blank">http://ladybug.no-ip.org/files/radials_final.png</a><br>
&gt;<br>
&gt; I had the idea of starting with a vector that starts in the centroid<br>
&gt; and ends up in the external ring (at any point), and therefore its<br>
&gt; length equals the radius; to make things simple I choose a point that<br>
&gt; is in the same x-alignment as the centroid, and so the start angle in<br>
&gt; your code would be null. My start vector is something like this:<br>
&gt;<br>
&gt; <a href="http://ladybug.no-ip.org/files/start.png" target="_blank">http://ladybug.no-ip.org/files/start.png</a><br>
&gt;<br>
&gt; Than my idea, was to rotate this vector around the centroid, at a<br>
&gt; constant angle, and get the radials.<br>
&gt; Lets assume for simplicity that the angle is 90 degrees (PI/2 radians)<br>
&gt; and therefore I want to end up with four radials.<br>
&gt; As I compute the new locations of the rotated endpoint of the vector,<br>
&gt; I store this point on a stl container, so that in the end I can loop<br>
&gt; through all these locations and generate my vectors.<br>
&gt; Here is a GEOS version of my code:<br>
&gt;<br>
&gt;        //////////GEOS VERSION /////<br>
&gt;        std::vector&lt;geos::geom::Point*&gt; pts;<br>
&gt;<br>
&gt;        geos::geom::GeometryFactory factory;<br>
&gt;        geos::geom::Coordinate coordC(ogrCentroid.getX(),ogrCentroid.getY());<br>
&gt;<br>
&gt;        //create centroid from given point<br>
&gt;        geos::geom::Point* centroid = factory.createPoint(coordC);<br>
&gt;<br>
&gt;        //create start pt as any point on the perimeter (for instance, a<br>
&gt; point aligned in x with the centroid)<br>
&gt;        geos::geom::Coordinate coordS(ogrCentroid.getX()+radius,ogrCentroid.getY());<br>
&gt;        geos::geom::Point* startPt = factory.createPoint(coordS);<br>
&gt;<br>
&gt;        pts.push_back(startPt);<br>
&gt;<br>
&gt;        //nr radials=4; angle=90 deg= PI/2<br>
&gt;        double fangle=PI/2.0;<br>
&gt;<br>
&gt;        for (size_t i=0; i &lt;4; ++i){<br>
&gt;<br>
&gt;                double x=pts.back()-&gt;getX();<br>
&gt;                double y=pts.back()-&gt;getY();<br>
&gt;<br>
&gt;                double rx=x*cos(fangle)-y*sin(fangle);<br>
&gt;                double ry=x*sin(fangle)+y*cos(fangle);<br>
&gt;<br>
&gt;                geos::geom::Coordinate coords(x+rx,y+ry);<br>
&gt;                geos::geom::Point* aPoint = factory.createPoint(coords);<br>
&gt;<br>
&gt;                pts.push_back(aPoint);<br>
&gt;        }<br>
&gt;<br>
&gt; Let me mention that this code is *not* doing what I want, since:<br>
&gt; - I am getting the wrong angle between the start point and the first<br>
&gt; iteration point;<br>
&gt; - the angles do not appear to be 90 degrees;<br>
&gt; - I think also the angles are not constant;<br>
&gt;<br>
&gt; Here is a screenshot of my output:<br>
&gt;<br>
&gt; <a href="http://ladybug.no-ip.org/files/output.png" target="_blank">http://ladybug.no-ip.org/files/output.png</a><br>
&gt;<br>
&gt; So I guess there must be some assumption (or more than one, actually)<br>
&gt; that is wrong in my code :-)<br>
&gt; Again, I would be very grateful for any observations or suggestions...<br>
&gt; thanks in advance for your help!<br>
&gt;<br>
&gt;                                       cheers,<br>
&gt;                                                     Jo<br>
&gt;<br>
&gt;<br>
&gt; ------------------------------<br>
&gt;<br>
&gt; _______________________________________________<br>
&gt; geos-devel mailing list<br>
&gt; <a href="mailto:geos-devel@lists.osgeo.org">geos-devel@lists.osgeo.org</a><br>
&gt; <a href="http://lists.osgeo.org/mailman/listinfo/geos-devel" target="_blank">http://lists.osgeo.org/mailman/listinfo/geos-devel</a><br>
&gt;<br>
</div></div>&gt; End of geos-devel Digest, Vol 82, Issue 25<br>
&gt; ******************************************<br>
&gt;<br>
<font color="#888888"><br>
<br>
<br>
--<br>
&quot;#define QUESTION ((bb) || !(bb))&quot;  (Shakespeare)<br>
</font><div><div></div><div class="h5">_______________________________________________<br>
geos-devel mailing list<br>
<a href="mailto:geos-devel@lists.osgeo.org">geos-devel@lists.osgeo.org</a><br>
<a href="http://lists.osgeo.org/mailman/listinfo/geos-devel" target="_blank">http://lists.osgeo.org/mailman/listinfo/geos-devel</a><br>
</div></div></blockquote></div><br>