HP Forums
Circle with interior arc segments - Printable Version

+- HP Forums (https://www.hpmuseum.org/forum)
+-- Forum: HP Calculators (and very old HP Computers) (/forum-3.html)
+--- Forum: HP Prime (/forum-5.html)
+--- Thread: Circle with interior arc segments (/thread-3056.html)



Circle with interior arc segments - DrD - 02-10-2015 06:45 PM

How would one calculate and plot circular arc segments laying totally within a semi-circle? Each segment begins at the right hand side (0*pi), and intersects the semi-circle circumference on pi/6, 2*pi/6, 3*pi/6 ... 6*pi/6, boundary intervals?

This is the idea, but method needs work!:
Code:

EXPORT Circ()
BEGIN
LOCAL a;
DIMGROB(G1,320,240);

ARC_P(G1,156,109,105,0,pi,RGB(255,0,0));  //  Semicircle center: (156,109), radius: 105 pixels
LINE_P(G1,51,109,261,109,RGB(255,0,0));  

FOR a  FROM 0 TO pi STEP pi/6 DO
  LINE_P(G1,156,109,156+ROUND(105*COS(a),1),109-ROUND(105*SIN(a),1),RGB(210,210,210));  //  pi/6 segment indicator
  ARC_P(G1,261,105*SIN(a)/2,105*COS(a),pi,3*pi/2,RGB(0,0,255));  //  This approach isn't working ...
END;

BLIT_P(G0,G1);
DRAWMENU("");
FREEZE;

END;

Thanks!


RE: Circle with interior arc segments - Thomas_Sch - 02-11-2015 02:12 PM

I did a little playing around with your code.
Don't know, if this helps.
Code:

EXPORT Circ()
BEGIN
 LOCAL a;
 LOCAL red:=  RGB(255,0,0);
 LOCAL blue:= RGB(0,0,255);
 LOCAL grey:= RGB(210,210,210);
 LOCAL lgrey:=RGB(210,210,00);
 LOCAL cx:=156, cy:=109, r:=105;
 LOCAL x2, y2, r2, x3, y3, r3; 

 DIMGROB(G1,320,240);
 RECT_P(G0);
 LINE_P(G0,cx+r+1,cy,cx+r+1,0,blue);
 //     G   x   y  r  w1  w2
 ARC_P(G0, cx, cy, r, 0,  pi, red);  // Semicircle center: (156,109), radius: 105 pixels
 LINE_P(G0, cx-r, cy, cx+r, cy, red);  // 

 FOR a  FROM 0 TO pi STEP pi/12 DO
    x2:= cx+ROUND(r*COS(a),1); 
    r2:= r*SIN(a);  
    y2:= cy-ROUND(r2,1); 

    LINE_P(G0, cx, cy, x2, y2, grey);  //  pi/6 segment indicator
    x3:= cx+r;
    r3:= (r*SIN(a))/COS(a);
    y3:= cy-r3;
    LINE_P(G0, x2, y2, x3, y3, lgrey); 
      //     G   x     y           r        w1    w2
      ARC_P(G0, x3  , y3,         r3,      1/2*pi, 3/2*pi, blue);  
    //ARC_P(G0, cx+r, r*SIN(a)/2, r*COS(a), pi, 3*pi/2,blue);  //  This approach isn't working ...
    WAIT(-1); 
 END;

 // BLIT_P(G0,G1);
 DRAWMENU("");
 FREEZE;

END;



RE: Circle with interior arc segments - Han - 02-11-2015 04:11 PM

I'm not sure I understand the question at hand. Based on the original code, is the i-th blue arc supposed to intersect the red semicircle at angles 0 and i*pi/6 for i from 0 to 6 (angles relative to the center of the red semicircle? It seems to me that more information is needed. There are infinitely many circles that will intersect your red semicircle at only two points. Do the blue arcs have to intersect the red semicircle at right angles, perhaps (i.e. Poincare' disk model)?


RE: Circle with interior arc segments - DrD - 02-11-2015 04:28 PM

Thanks! Your response is very helpful! With your help, I discovered that the factor r3:= (r*SIN(a))/COS(a) is the key, and stepping by pi/12 is necessary. Also, that the loop 'a' runs to pi/2, after which the x and y parameters go out of bounds.

Would you have any insight on how to constrain the segments to within the semi-circle, as a function of the 'a' angle in the loop? One way might be to test for the semi-circle radius (x,y) endpoint, but it seems like the arc segment length (w1,w2) should also be a trig function of the step angle, I just haven't quite figured out how that would work.

Geometry, unfortunately, was never my fine suit.

-Dale-


RE: Circle with interior arc segments - DrD - 02-11-2015 04:49 PM

Han,

Thomas has the right idea. For this purpose, there is only one circle segment for each of the 6 radii, that is to intersect the semi-circle tangent to its i*30° point. The segments are to be totally contained within the interior of the semi-circle.

The radius of those 6 circle segments was my difficulty, (since the two points are known), but two points don't determine a circle, and it just got deeper the more I worked with the problem. Thomas worked it out, nicely. Now if I could get a wrench on how to keep the arc lengths between the right hand edge, and it's semi-circle-circumference tangent, it would be a good day!

I can still hear my calculus professor, "Dale, your problem is you need to take a geometry class!" That was in 1966, and she was exactly right!

-Dale-


RE: Circle with interior arc segments - Thomas_Sch - 02-11-2015 05:17 PM

(02-11-2015 04:28 PM)DrD Wrote:  ...
Would you have any insight on how to constrain the segments to within the semi-circle, as a function of the 'a' angle in the loop? One way might be to test for the semi-circle radius (x,y) endpoint, but it seems like the arc segment length (w1,w2) should also be a trig function of the step angle, I just haven't quite figured out how that would work. ..
Hello Dale,

I thought about that, like I did the trial-and-error-steps before (with help of some plain old-style paper scribbles), but till now I'm missing the solution.

Looking for help & posible suggestions, I found this documents, maybe it's helpful:
http://www.ittc.ku.edu/~jstiles/723/handouts/2_4_The_Smith_Chart_package.pdf (very long, and impressive),
http://whites.sdsmt.edu/classes/ee382/notes/382Lecture22.pdf, and http://www.siart.de/lehre/smishort.pdf (see pages 12..14, it's in german).

HTH Thomas

edit: I tested some triangle calculations. (again with paper).
The missing arc seems to be 2 * (pi/2) - a, see variable b.
Code:

EXPORT Circ()
BEGIN
 LOCAL a;
 LOCAL red:=  RGB(255,0,0);
 LOCAL blue:= RGB(0,0,255);
 LOCAL grey:= RGB(210,210,210);
 LOCAL lgrey:=RGB(210,210,00);
 LOCAL cx:=156, cy:=109, r:=105;
 LOCAL x2, y2, r2, x3, y3, r3, b; 

 DIMGROB(G1,320,240);
 RECT_P(G0);
 LINE_P(G0,cx+r+1,cy,cx+r+1,0,blue);
 //     G   x   y  r  w1  w2
 ARC_P(G0, cx, cy, r, 0,  pi, red);  // Semicircle center: (156,109), radius: 105 pixels
 LINE_P(G0, cx-r, cy, cx+r, cy, red);  // 

 
 FOR a  FROM 0 TO pi STEP pi/12 DO
    x2:= cx+ROUND(r*COS(a),1); 
    r2:= r*SIN(a);  
    y2:= cy-ROUND(r2,1); 

    LINE_P(G0, cx, cy, x2, y2, grey);  //  pi/6 segment indicator
    x3:= cx+r;
    r3:= (r*SIN(a))/COS(a);
    y3:= cy-r3;
    LINE_P(G0, x2, y2, x3, y3, lgrey);
    b:= 2*(pi/2 - a);
    
   //     G   x     y           r        w1      w2
    ARC_P(G0, x3  , y3,         r3,      3/2*pi-b, 3/2*pi, blue);  
 // ARC_P(G0, x3  , y3,         r3,      1/2*pi, 3/2*pi, blue);  
 // ARC_P(G0, cx+r, r*SIN(a)/2, r*COS(a), pi, 3*pi/2,blue);  //  This approach isn't working ...
    WAIT(-1); 
 END;

 // BLIT_P(G0,G1);
 DRAWMENU("");
 FREEZE;

END;



RE: Circle with interior arc segments - DrD - 02-12-2015 02:16 PM

I have pruned the routine still more. The arc segments are now "close" to meeting the circumference, as needed. I wonder why they don't meet the circumference exactly? I could still use a little help here (thanks!):

Code:

EXPORT Circ()
BEGIN
 LOCAL a;
 LOCAL red:=  RGB(255,0,0);
 LOCAL blue:= RGB(0,0,255);
 LOCAL grey:= RGB(210,210,210);
 LOCAL lgrey:=RGB(210,210,00);
 LOCAL cx:=156, cy:=109, r:=105;      // Center: (156,109), Radius: 105 (pixels)
 LOCAL x2, y2, r2, x3, y3, r3; 

 RECT_P(G0);
 
 //         G   x      y    r  w1  w2    Color
 ARC_P(G0, cx,   cy,  r, 0,     2*pi, red);        // Semicircle center: (156,109), radius: 105 pixels
 LINE_P(G0, cx-r, cy, cx+r, cy, red);         // Equator

 FOR a  FROM -pi TO pi STEP pi/12 DO
  
    x2:= cx+r*COS(a);
    y2:= cy-r2; 

    r2:= r*SIN(a); 
    r3:= (r*SIN(a))/COS(a);
   
    x3:= cx+r;
    y3:= cy-r3;   
   
    if abs(a) < ROUND(pi/2,7)  then  
      //        G    x      y            r      w1                 w2            Color
     ARC_P(G0, x3  , y3,         r3,     2*a+1/2*pi,  -pi/2,           blue);    //  north semicircle  
     ARC_P(G0, x3  , y3,        -r3,     pi/2,              2*a-1/2*pi, blue);    //  south semicircle    
    end;

 END;

 DRAWMENU("");
 FREEZE;

END;



RE: Circle with interior arc segments - Thomas_Sch - 02-12-2015 06:00 PM

I added temporarily printing for some variables, to see the calculated values, also temporarily made different colors for north and sourth semicircles.
The calculations are easy and should be correct. Maybe the values for the big arcs are to big? (r3 could also be calculated by tan(a)*r ).
I am currently stumped, why the semicircles are not hitting the red circle.
Maybe it's better to use the cartesian drawing functions (without _P) than the pixel drawing functions. But I'm not shure.

Code:

EXPORT Circ() 
BEGIN
 LOCAL a;
 LOCAL red:=  RGB(255,0,0);
 LOCAL blue:= RGB(0,0,255);
 LOCAL green:= RGB(0,255,0);
 LOCAL grey:= RGB(210,210,210);
 LOCAL lgrey:=RGB(210,210,00);
 LOCAL white:=RGB(255,255,255);
 LOCAL cx:=156, cy:=109, r:=105; // Center: (156,109), Radius: 105 (pixels)
 LOCAL x2, y2, r2, x3, y3, r3, str; 

 RECT_P(G0);
 //     G   x  y   r  w1  w2   Color 
 ARC_P(G0, cx, cy, r, 0, 2*pi, red); 
  // Semicircle center: (156,109), radius: 105 pixels 
 LINE_P(G0, cx-r, cy, cx+r, cy, red);    // Equator

 FOR a  FROM -pi TO pi STEP pi/12 DO
    //  x2:= cx+r*COS(a);
    //  y2:= cy-r2; 
    //  r2:= r*SIN(a); 
    //  r3:= r*SIN(a)/COS(a);
    r3:= r*TAN(a);
    x3:= cx+r;
    y3:= cy-r3; 
    IF abs(a) < ROUND(pi/2,7)  then  
      RECT_P(G0,5,220,300,240,white,white);
      str:= "a: "+STRING(a,2,3)+"  x3:"+STRING(x3,1,-1)+"  y3: "+STRING(y3,2,3)+"  r3: "+STRING(r3,2,3);  
      TEXTOUT_P(str, 5,220, 2);
      //    G   x   y    r   w1          w2    Color
      ARC_P(G0, x3, y3, r3,  2*a+1/2*pi, -pi/2, blue);   // north semicircle  
      ARC_P(G0, x3, y3, -r3, pi/2, 2*a-1/2*pi, green);   // south semicircle 
      WAIT(-1);
    END;
 END;
 DRAWMENU("");
 FREEZE;
END;

Edit:
Could it be possible, to draw a big "picture" greater than the display, and only show a part of this great picture? How big can be the GROBs?


RE: Circle with interior arc segments - Tim Wessman - 02-12-2015 06:06 PM

(02-12-2015 06:00 PM)Thomas_Sch Wrote:  I am currently stumped, why the semicircles are not hitting the red circle.

First thought I have is that the ARC drawing routine uses 4096 steps to represent a circle. Larger radii will probably hit the size that rounding can impact things.


RE: Circle with interior arc segments - Thomas_Sch - 02-12-2015 06:31 PM

(02-12-2015 06:06 PM)Tim Wessman Wrote:  
(02-12-2015 06:00 PM)Thomas_Sch Wrote:  I am currently stumped, why the semicircles are not hitting the red circle.

First thought I have is that the ARC drawing routine uses 4096 steps to represent a circle. Larger radii will probably hit the size that rounding can impact things.

Thanks for the hint!
Is it possible to get better results with the non- "_P" routines (using ARC instead of ARC_P)?
(sorry, but i don't have examples using ARC, LINE, etc)


RE: Circle with interior arc segments - Jonathan Cameron - 02-12-2015 06:34 PM

Could we see a plot of the results?


RE: Circle with interior arc segments - Thomas_Sch - 02-12-2015 06:58 PM

(02-12-2015 06:34 PM)Jonathan Cameron Wrote:  Could we see a plot of the results?
Here it is:
[attachment=1613]


RE: Circle with interior arc segments - Tim Wessman - 02-12-2015 08:11 PM

(02-12-2015 06:31 PM)Thomas_Sch Wrote:  Thanks for the hint!
Is it possible to get better results with the non- "_P" routines (using ARC instead of ARC_P)?
(sorry, but i don't have examples using ARC, LINE, etc)

No, it is the low level drawing routine. To get any reasonable speed in drawing precise circles you have to go into integer based routines which have some tradeoffs.