From: <and...@us...> - 2011-08-03 12:45:53
|
Revision: 11842 http://plplot.svn.sourceforge.net/plplot/?rev=11842&view=rev Author: andrewross Date: 2011-08-03 12:45:46 +0000 (Wed, 03 Aug 2011) Log Message: ----------- Update plarc to use the rotate option to plot ellipses which have the major axis rotated relative to the X-axis. Also work around bug with filled ellipses which caused crash. Modified Paths: -------------- trunk/doc/docbook/src/api.xml trunk/src/plarc.c Modified: trunk/doc/docbook/src/api.xml =================================================================== --- trunk/doc/docbook/src/api.xml 2011-08-03 02:19:05 UTC (rev 11841) +++ trunk/doc/docbook/src/api.xml 2011-08-03 12:45:46 UTC (rev 11842) @@ -362,6 +362,7 @@ <paramdef><parameter>b</parameter></paramdef> <paramdef><parameter>angle1</parameter></paramdef> <paramdef><parameter>angle2</parameter></paramdef> + <paramdef><parameter>rotate</parameter></paramdef> <paramdef><parameter>fill</parameter></paramdef> </funcprototype> </funcsynopsis> @@ -429,7 +430,7 @@ </term> <listitem> <para> - Starting angle of the arc. + Starting angle of the arc relative to the semimajor axis. </para> </listitem> </varlistentry> @@ -440,12 +441,23 @@ </term> <listitem> <para> - Ending angle of the arc. + Ending angle of the arc relative to the semimajor axis. </para> </listitem> </varlistentry> <varlistentry> <term> + <parameter>rotate</parameter> + (<literal>PLFLT</literal>, input) + </term> + <listitem> + <para> + Angle of the semimajor axis relative to the X-axis. + </para> + </listitem> + </varlistentry> + <varlistentry> + <term> <parameter>fill</parameter> (<literal>PLBOOL</literal>, input) </term> @@ -462,7 +474,7 @@ <itemizedlist> <listitem> <para> - General: <function>plarc(x, y, a, b, angle1, angle2, fill)</function> + General: <function>plarc(x, y, a, b, angle1, angle2, rotate, fill)</function> </para> </listitem> </itemizedlist> Modified: trunk/src/plarc.c =================================================================== --- trunk/src/plarc.c 2011-08-03 02:19:05 UTC (rev 11841) +++ trunk/src/plarc.c 2011-08-03 12:45:46 UTC (rev 11842) @@ -21,12 +21,9 @@ #include "plplotP.h" -#define CIRCLE_SEGMENTS ( PL_MAXPOLY - 1 ) +#define CIRCLE_SEGMENTS ( PL_MAXPOLY - 2 ) #define DEG_TO_RAD( x ) ( ( x ) * M_PI / 180.0 ) -#define PLARC_POINT_X( x, a, b, theta ) ( ( x ) + ( ( a ) * cos( theta ) ) ) -#define PLARC_POINT_Y( y, a, b, theta ) ( ( y ) + ( ( b ) * sin( theta ) ) ) - //-------------------------------------------------------------------------- // plarc_approx : Plot an approximated arc with a series of lines // @@ -40,12 +37,17 @@ PLFLT theta0, theta_step, theta, d_angle; PLINT segments; PLFLT xs[CIRCLE_SEGMENTS + 1], ys[CIRCLE_SEGMENTS + 1]; + PLFLT cphi,sphi,ctheta,stheta; // The difference between the start and end angles d_angle = DEG_TO_RAD( angle2 - angle1 ); if ( fabs( d_angle ) > M_PI * 2.0 ) d_angle = M_PI * 2.0; + // Calculate cosine and sine of angle of major axis wrt the x axis + cphi = cos(DEG_TO_RAD(rotate)); + sphi = sin(DEG_TO_RAD(rotate)); + // The number of line segments used to approximate the arc segments = fabs( d_angle ) / ( 2.0 * M_PI ) * CIRCLE_SEGMENTS; // Always use at least 2 arc points, otherwise fills will break. @@ -61,8 +63,10 @@ for ( i = 0; i < segments; i++ ) { theta = theta0 + theta_step * (PLFLT) i; - xs[i] = PLARC_POINT_X( x, a, b, theta ); - ys[i] = PLARC_POINT_Y( y, a, b, theta ); + ctheta = cos(theta); + stheta = sin(theta); + xs[i] = x + a*ctheta*cphi - b*stheta*sphi; + ys[i] = y + a*ctheta*sphi + b*stheta*cphi; } if ( fill ) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |