Would anyone like to share a ULP that draws a wire shaped by a polar
function.
For example R=(2*L)\(1+cos(Theta))
L=(n*lambda)\4
Theta= angle from x axis
R= length of the vector
Would anyone like to share a ULP that draws a wire shaped by a polar
function.
For example R=(2*L)\(1+cos(Theta))
L=(n*lambda)\4
Theta= angle from x axis
R= length of the vector
Kujtim Iljazi wrote:
Would anyone like to share a ULP that draws a wire shaped by a polar
function.
For example R=(2*L)\(1+cos(Theta))
L=(n*lambda)\4
Theta= angle from x axis
R= length of the vector
/* parabolic.ulp
The key thing to remember seems to be that the ULP trig
functions all work on arguments in radians, while the
polar coordinates you use when specifying points to the
wire command are in degrees.
*
watch out for cos(t) = -1 (divide by 0) at theta = 180 !
*/
/* User parameters to be changed */
real lambda = 20.0;
real n = 4;
real theta_start = -100.0, theta_end = 100.0 ;
real delta_theta = 10.0;
/* Actual code starts here */
string h, cmd ="";
real theta;
/* convert degress to radians for trig math. */
real d2r(real deg)
{
return(deg * PI)/180.0;
}
/* main */
sprintf(h, "grid mm; mark (0 0);\n set wire_bend 2; wire "); cmd +=h;
real L = n * lambda/4;
for (theta = theta_start; theta <= theta_end; theta += delta_theta) {
real r = (2.0*L)/(1.00+cos(d2r(theta))); // Calculate R
sprintf(h, " (P %f %f)", r, theta); // add next point to wire.
cmd += h;
}
cmd += ";";
exit(cmd);
Kujtim Iljazi wrote:
Would anyone like to share a ULP that draws a wire shaped by a polar
function.
For example R=(2*L)\(1+cos(Theta))
L=(n*lambda)\4
Theta= angle from x axis
R= length of the vector
/* parabolic.ulp
The key thing to remember seems to be that the ULP trig
functions all work on arguments in radians, while the
polar coordinates you use when specifying points to the
wire command are in degrees.
*
watch out for cos(t) = -1 (divide by 0) at theta = 180 !
*/
/* User parameters to be changed */
real lambda = 20.0;
real n = 4;
real theta_start = -100.0, theta_end = 100.0 ;
real delta_theta = 10.0;
/* Actual code starts here */
string h, cmd ="";
real theta;
/* convert degress to radians for trig math. */
real d2r(real deg)
{
return(deg * PI)/180.0;
}
/* main */
sprintf(h, "grid mm; mark (0 0);\n set wire_bend 2; wire "); cmd +=h;
real L = n * lambda/4;
for (theta = theta_start; theta <= theta_end; theta += delta_theta) {
real r = (2.0*L)/(1.00+cos(d2r(theta))); // Calculate R
sprintf(h, " (P %f %f)", r, theta); // add next point to wire.
cmd += h;
}
cmd += ";";
exit(cmd);