Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
A Christmas puzzle
Message
De
24/12/2003 18:41:44
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Autre
Divers
Thread ID:
00861878
Message ID:
00862010
Vues:
18
Rob,

Thanks for your reply. I had completely missed to DTOR function and assumed the +ve Y axis pointed upwards for my calcs.

After re-reading Viv's puzzle, I think you are right. If Viv is willing to restrict arc angles to no greater than 178 degree then why not :-
PrintCoords(30,60,100)
PrintCoords(45,150,100)
PrintCoords(300,180,100)
PrintCoords(180,240,100)
PrintCoords(300,122,100) && Nearly 180 deg

* params are the starting and ending angle in degrees,
* and the radius of the larger circle.
* this code assumes that the distance from angle1 to angle2 is not more than 178 deg.
FUNCTION PrintCoords( tnAngle1, tnAngle2, tnRadius )

   * Enclose the part doughnut with an isoceles triangle, apex at 0,0
   * and base a tangent to the larger arc.
   * Calc length of side of triangle
   l = ABS(tnRadius/(COS(DTOR((tnAngle1 - tnAngle2)/2))))
   
   DIMENSION aCoords[4,2]
   * Start and end at origin
   aCoords[1,1] = 0
   aCoords[1,2] = 0
   aCoords[4,1] = 0
   aCoords[4,2] = 0 
   * Coordinates of base vertices
   aCoords[2,1] =  l*COS(DTOR(tnAngle1))
   aCoords[2,2] = -l*SIN(DTOR(tnAngle1))
   aCoords[3,1] =  l*COS(DTOR(tnAngle2))
   aCoords[3,2] = -l*SIN(DTOR(tnAngle2))

   * Print Coords
   CLEAR
   FOR ii = 1 TO 3
       @ 15 + ii, 3  SAY "(" + TRANSFORM(aCoords[ii,1]) + "," + TRANSFORM(aCoords[ii,2]) + ")"
   ENDFOR

   * Sorry but I'm the visual sort, I have to draw it.
   =ShowCoords( tnAngle1, tnAngle2, tnRadius)
   
ENDFUNC

FUNCTION ShowCoords( tnAngle1, tnAngle2, tnRadius)

   lnExtra   = 20
   lnOffSetX = tnRadius + lnExtra + 30
   lnOffSetY = lnOffSetX

   * Draw axes
   _SCREEN.Line(lnOffSetX - tnRadius - lnExtra,;
                lnOffSetY                     ,;
                lnOffSetX + tnRadius + lnExtra,;
                lnOffSetY)
   _SCREEN.Line(lnOffSetX                     ,;
                lnOffSetY - tnRadius - lnExtra,;
                lnOffSetX                     ,;
                lnOffSetY + tnRadius + lnExtra)
                
   * Draw arcs
   lnAngle  = DTOR(tnAngle1)
   lnArcIncrement = (DTOR(tnAngle1) - DTOR(tnAngle2))/10
   FOR t = 1 TO 10
      nXCoord1 = lnOffSetX + tnRadius*COS(lnAngle)
      nYCoord1 = lnOffSetY - tnRadius*SIN(lnAngle)
      lnAngle  = lnAngle - lnArcIncrement
      nXCoord2 = lnOffSetX + tnRadius*COS(lnAngle)
      nYCoord2 = lnOffSetY - tnRadius*SIN(lnAngle)
      _SCREEN.Line(nXCoord1, nYCoord1, nXCoord2, nYCoord2)
   ENDFOR
    
   * Draw triangle
   FOR t =1 TO 3
      _SCREEN.Line(lnOffSetX+aCoords[t,1]  , lnOffSetY+aCoords[t,2]  ,;
                   lnOffSetX+aCoords[t+1,1], lnOffSetY+aCoords[t+1,2])
   ENDFOR
   

   WAIT WINDOW

ENDFUNC
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform