Graphic Challenge
Richard Ashbery (8349) 42 posts |
I’ve been looking at a Reuleaux Triangle (download below). Trying to create it in BASIC is certainly challenging – tried a complex parametric equation (off web) which fails when tested (bracket in the wrong place, maybe). Anyone fancy having ago at coding it? |
Chris Hall (132) 3554 posts |
If this is the same shape as a 50 p piece but with three sides (i.e. has constant width when it rotates) then the following would do it, using MakeDraw:
These would be Bezier curves so not absolutely precise. They are just three circular arcs. |
Steve Fryatt (216) 2105 posts |
Something like
where |
David J. Ruck (33) 1635 posts |
That’s not a Reuleaux Triangle, it’s the rotor out of my car |
Clive Semmens (2335) 3276 posts |
Are they still making those, or do you have quite an old car? What model? |
John McCartney (426) 147 posts |
I suspect Druck has/had a Mazda rotary, not the old NSU Ro80. |
David J. Ruck (33) 1635 posts |
I’ve got an 2009 RX-8 R3, they stopped making them in 2012. I’m thinking of getting something more economical before the petrol ban comes in, may be a 4.4L V8. |
Richard Ashbery (8349) 42 posts |
Reply to Chris I’ll certainly have a look at your suggestion. I’ve never used MakeDraw so would be a good time to investigate. I prefer a standalone program as I can ‘Chain’ others for a pseudo slideshow. |
Richard Ashbery (8349) 42 posts |
Interestingly Steve your program using coordinates to render shape near the centre of the screen draws almost the whole circle leaving out the convex part along the triangle edges (see below). Removing the triangle actually creates a rather nice pattern. The coordinates with smaller values renders an accurate Reuleaux triangle. Coordinates seem quite critical. What I need now is to be able to rotate the shape around the screen centre. |
Clive Semmens (2335) 3276 posts |
As it rotates, do you not need it also to shift side to side or up and down, like the Wankel engine’s rotor? |
Steve Drain (222) 1620 posts |
A slightly different take: DEFPROCReuleaux(radius,rotate) LOCAL r(),rotate() DIM r(2,1),rotate(1,1) rotate()=COSrotate,SINrotate,-SINrotate,COSrotate sinrad=radius*SIN(PI/6):REM =radius/2 cosrad=radius*COS(PI/6):REM =sinrad*SQR3 r()=0,radius,-cosrad,-sinrad,+cosrad,-sinrad r()=r().rotate() MOVE r(0,0),r(0,1) DRAW r(1,0),r(1,1) DRAW r(2,0),r(2,1) DRAW r(0,0),r(0,1) REM MOVE r(0,0),r(0,1) not required with triangle MOVE r(1,0),r(1,1) PLOT 165,r(2,0),r(2,1) MOVE r(0,0),r(0,1) PLOT 165,r(1,0),r(1,1) MOVE r(2,0),r(2,1) PLOT 165,r(0,0),r(0,1) CIRCLE 0,0,radius ENDPROC This draws the triangle, the reuleaux and the circumscribing circle about the
That happens here, but ought to be compensated for. |
David R. Lane (77) 766 posts |
Here is my version of a BASIC program to draw the Reuleaux triangle using nested FOR loops instead of Procedures. I don’t know why, but I can’t get the third line to come out correctly: On the end should be (3), so that B is A divided by the square root of 3. A = 200 MODE 31 FOR M = 0 TO 2 END This program can be easily generalised to ‘regular curvilinear polygons’ with any number of sides. |
David R. Lane (77) 766 posts |
Second attempt at my post above. Here is my version of a BASIC program to draw the Reuleaux triangle using nested FOR loops instead of Procedures. A = 200 N = 100 B = A/SQR(3) MODE 31 MOVE 640 - B/2, 512 + A/2 FOR M = 0 TO 2 Phi = 2*M*PI/3: Theta = 5*PI/6 + Phi C1 = B*COS(Phi): C2 = B*SIN(Phi) FOR K = 1 TO N DRAW 640 + C1 + A*COS(Theta + K*PI/(3*N)), 512 + C2 + A*SIN(Theta + K*PI/(3*N)) NEXT K NEXT M END This program can be easily generalised to ‘regular curvilinear polygons’ with any number of sides. |
Richard Ashbery (8349) 42 posts |
Many thanks for the coding – what an great response! One of the most interesting is Steve Drain’s example. Rotating the shape is simple. Only 2 parameters (radius and rotate) required. Wonder if animation would benefit from contra-rotating ‘Reuleaux Triangles’- I’ll try it. |
Steve Drain (222) 1620 posts |
BASIC’s array operations and ORIGIN are your friends. ;-) The example I posted was specific for 3 sides. There is a generalised set of routines at: http://www.kappa.me.uk/Miscellaneous/swReuleaux000.zipHave fun. |
David R. Lane (77) 766 posts |
Here is another program that includes animation. MODE 31 w = 120 : REM w is the half-width of the guide. b = 2*w/SQR(3) theta = 0 S = -41.89 H = 511 - b MOVE 640-w,0 DRAW 640-w,1023 MOVE 640+w,0 DRAW 640+w,1023 DIM V0(1,2), V(1,2), R(1,1), F(1,2), L(1,2) V0() = 0, -w, w, b, -b/2, -b/2 L() = 640, 640, 640, 512, 512, 512 V() = 640, 640-w, 640+w, 1023, 1023-3*b/2, 1023-3*b/2 MOVE V(0,0),V(1,0) DRAW V(0,1),V(1,1) DRAW V(0,2),V(1,2) DRAW V(0,0),V(1,0) MOVE V(0,1),V(1,1) PLOT 165,V(0,2),V(1,2) MOVE V(0,0),V(1,0) PLOT 165,V(0,1),V(1,1) MOVE V(0,2),V(1,2) PLOT 165,V(0,0),V(1,0) PROCwait(3) FOR I=0 TO 18 MOVE 640-w,0 DRAW 640-w,1023 MOVE 640+w,0 DRAW 640+w,1023 Y = S * I + H theta = I*PI/9 M = FNquot(theta,PI/3) : phi = FNremain(theta,PI/3) REM alpha = 2*M*PI/3: beta = 5*PI/6 + alpha E = (-1)^M * (w - b* COS(phi-PI/6)) R() = COS(theta), -SIN(theta), SIN(theta), COS(theta) V() = R().V0() V() = V() + L() REM This block plots the diagram without the correction for the disc centre. REM MOVE V(0,0),V(1,0) REM DRAW V(0,1),V(1,1) REM DRAW V(0,2),V(1,2) REM DRAW V(0,0),V(1,0) F() = E,E,E,Y,Y,Y V() = V() + F() MOVE V(0,0),V(1,0) DRAW V(0,1),V(1,1) DRAW V(0,2),V(1,2) DRAW V(0,0),V(1,0) MOVE V(0,1),V(1,1) PLOT 165,V(0,2),V(1,2) MOVE V(0,0),V(1,0) PLOT 165,V(0,1),V(1,1) MOVE V(0,2),V(1,2) PLOT 165,V(0,0),V(1,0) PROCwait(1) CLG NEXT I END DEF FNquot(T,D) = INT(T/D) DEF FNremain(T,D) = T - INT(T/D) * D DEF PROCwait(delay) TIME = 0 REPEAT UNTIL TIME >= 100*delay ENDPROC The program needs tidying up, but it does show the Reuleaux triangle rolling |