Post Reply 
Circle with interior arc segments
02-10-2015, 06:45 PM
Post: #1
Circle with interior arc segments
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!
Find all posts by this user
Quote this message in a reply
02-11-2015, 02:12 PM
Post: #2
RE: Circle with interior arc segments
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;
Find all posts by this user
Quote this message in a reply
02-11-2015, 04:11 PM
Post: #3
RE: Circle with interior arc segments
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)?

Graph 3D | QPI | SolveSys
Find all posts by this user
Quote this message in a reply
02-11-2015, 04:28 PM
Post: #4
RE: Circle with interior arc segments
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-
Find all posts by this user
Quote this message in a reply
02-11-2015, 04:49 PM
Post: #5
RE: Circle with interior arc segments
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-
Find all posts by this user
Quote this message in a reply
02-11-2015, 05:17 PM (This post was last modified: 02-11-2015 05:52 PM by Thomas_Sch.)
Post: #6
RE: Circle with interior arc segments
(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/hand...ackage.pdf (very long, and impressive),
http://whites.sdsmt.edu/classes/ee382/no...ture22.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;
Find all posts by this user
Quote this message in a reply
02-12-2015, 02:16 PM
Post: #7
RE: Circle with interior arc segments
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;
Find all posts by this user
Quote this message in a reply
02-12-2015, 06:00 PM (This post was last modified: 02-12-2015 06:19 PM by Thomas_Sch.)
Post: #8
RE: Circle with interior arc segments
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?
Find all posts by this user
Quote this message in a reply
02-12-2015, 06:06 PM
Post: #9
RE: Circle with interior arc segments
(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.

TW

Although I work for HP, the views and opinions I post here are my own.
Find all posts by this user
Quote this message in a reply
02-12-2015, 06:31 PM (This post was last modified: 02-12-2015 06:33 PM by Thomas_Sch.)
Post: #10
RE: Circle with interior arc segments
(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)
Find all posts by this user
Quote this message in a reply
02-12-2015, 06:34 PM
Post: #11
RE: Circle with interior arc segments
Could we see a plot of the results?
Visit this user's website Find all posts by this user
Quote this message in a reply
02-12-2015, 06:58 PM
Post: #12
RE: Circle with interior arc segments
(02-12-2015 06:34 PM)Jonathan Cameron Wrote:  Could we see a plot of the results?
Here it is:
   
Find all posts by this user
Quote this message in a reply
02-12-2015, 08:11 PM
Post: #13
RE: Circle with interior arc segments
(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.

TW

Although I work for HP, the views and opinions I post here are my own.
Find all posts by this user
Quote this message in a reply
Post Reply 




User(s) browsing this thread: 1 Guest(s)