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