Ludoke
This might be of interest with regards to G-Codes:
CNC Programming Handbook by Peter Smid. ISBN 0-8311-3136-5
It is very well written and explains everything about CNC.
drawin arcs
-
- Always Here
- Posts: 6425
- Joined: Fri Oct 23, 2009 2:33 am
- Location: Wales, UK
- Contact:
Re: drawin arcs
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
If it sounds simple, you have not grasped the complexity.
Re: drawin arcs
Michael,
I keep on struggling, I tried to put that demo gcode in your program, but I can't get it done.
The arc start and end are ok ,but not on the screen
I changed your code to a more understandable one for me
I keep on struggling, I tried to put that demo gcode in your program, but I can't get it done.
The arc start and end are ok ,but not on the screen
I changed your code to a more understandable one for me
Code: Select all
DataSection
demo:
Data.s "M3 S1000"
Data.s "G0 X-48.9778 Y14.8236"
Data.s "G0 Z1.0"
Data.s "G1 F300.0 Z-0.4"
Data.s "G3 F800.0 X-24.4829 Y0.6815 I19.3185 J5.1764"
Data.s "G1 X-14.8236 Y3.2697"
Data.s "G3 X-0.6815 Y27.7646 I-5.1764 J19.3185"
Data.s "G1 X-3.2697 Y37.4238"
Data.s "G3 X-27.7646 Y51.566 I-19.3185 J-5.1764"
Data.s "G1 X-37.4238 Y48.9778"
Data.s "G3 X-51.566 Y24.4829 I5.1764 J-19.3185"
Data.s "G1 X-48.9778 Y14.8236"
Data.s "G0 Z3.0"
Data.s ";end example "
EndDataSection
#Draw100=$FF000000
#Epsilon=0.0001
Global x_off.d,y_off.d
Global xstart.d,ystart.d,xend.d,yend.d
Global xcenter.d,ycenter.d
Global i.d,i2.d,j.d,j2.d
;-------------------------------------------------
xstart=-49 :ystart=15:xend=-24:yend=1 :i=19:j=5 ;i =relative to xstart ,j=relative to ystart
;i and j must invert
i=-i:j=-j
;xstart,ystart,xend,yend are absolute
x_off=300:y_off=300
;-------------------------------------------------------------------------
Procedure Arc(direction=0,color=#Black)
Protected.d ma,mb,wa,wb
ma=Sqr(Pow(i,2)+Pow(j,2));radius1 =19 ma=Sqr(Pow(start\x-m\x,2)+Pow(start\y-m\y,2))
xcenter=xstart-i ;-49-(-19)=-30
ycenter=ystart-j ;15-(-5)=20
i2=xend-xcenter ;-24-(-30)=6
j2=yend-ycenter ;1-20=-19
mb=Sqr(Pow(i2,2)+Pow(j2,2));radius2 mb=sqr(36+36)=19.92 mb=Sqr(Pow(stop\x-m\x,2)+Pow(stop\y-m\y,2))
If Abs(ma-mb)>#Epsilon ;if end and start differs more than 0.001 oops
Debug "Oops."
EndIf
wa=ATan2(i,j); atan2(-19,-5)=-2.8842689386
wa=Degree(wa)
wb=ATan2(i2,j2);atan2(6,-19)= -1.2649174554 wb=Angle(m,stop):Debug "eind="+wb
wb=Degree(wb)
Debug "start="+wa+" end="+wb
VectorSourceColor(#Draw100|color)
If direction
AddPathCircle(x_off+xcenter,y_off+ycenter,ma,wa,wb); AddPathCircle(m\x,m\y,ma,wa,wb) ;x,y center,straal,start ,end
Else
AddPathCircle(x_off+xcenter,y_off+ycenter,ma,wb,wa); AddPathCircle(m\x,m\y,ma,wb,wa)
EndIf
StrokePath(2)
If wa<0 :wa=wa+360:EndIf
If wb<0 :wb=wb+360:EndIf ;make positive
Debug "start=" +wa+" end="+wb
EndProcedure
;----------------------------------------------------------
Procedure Draw()
StartVectorDrawing(CanvasVectorOutput(0))
Arc(0,#Blue)
;Arc(1,#Cyan)
StopVectorDrawing()
EndProcedure
;-----------------------------------------------------------
OpenWindow(0,0,0,1500,1000,"")
CanvasGadget(0,0,0,1500,1000)
Draw()
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow
End
EndSelect
ForEver
- Michael Vogel
- Addict
- Posts: 2677
- Joined: Thu Feb 09, 2006 11:27 pm
- Contact:
Re: drawin arcs
Hm, not sure where are the problems, so I only changed the offset to be used in the vector output (TranslateCoordinates)...
...maybe you can give some more information about what's going wrong.
...maybe you can give some more information about what's going wrong.
Code: Select all
DataSection
demo:
Data.s "M3 S1000"
Data.s "G0 X-48.9778 Y14.8236"
Data.s "G0 Z1.0"
Data.s "G1 F300.0 Z-0.4"
Data.s "G3 F800.0 X-24.4829 Y0.6815 I19.3185 J5.1764"
Data.s "G1 X-14.8236 Y3.2697"
Data.s "G3 X-0.6815 Y27.7646 I-5.1764 J19.3185"
Data.s "G1 X-3.2697 Y37.4238"
Data.s "G3 X-27.7646 Y51.566 I-19.3185 J-5.1764"
Data.s "G1 X-37.4238 Y48.9778"
Data.s "G3 X-51.566 Y24.4829 I5.1764 J-19.3185"
Data.s "G1 X-48.9778 Y14.8236"
Data.s "G0 Z3.0"
Data.s ";end example "
EndDataSection
#Draw100=$FF000000
#Epsilon=0.0001
Global zoom=3
Global x_off.d,y_off.d
Global xstart.d,ystart.d,xend.d,yend.d
Global xcenter.d,ycenter.d
Global i.d,i2.d,j.d,j2.d
;-------------------------------------------------
xstart=-49 :ystart=15:xend=-24:yend=1 :i=19:j=5 ;i =relative to xstart ,j=relative to ystart
;i and j must invert
i=-i:j=-j
;xstart,ystart,xend,yend are absolute
x_off=300:y_off=300
;-------------------------------------------------------------------------
Procedure Arc(direction=0,color=#Black)
Protected.d ma,mb,wa,wb
ma=Sqr(Pow(i,2)+Pow(j,2));radius1 =19 ma=Sqr(Pow(start\x-m\x,2)+Pow(start\y-m\y,2))
xcenter=xstart-i ;-49-(-19)=-30
ycenter=ystart-j ;15-(-5)=20
i2=xend-xcenter ;-24-(-30)=6
j2=yend-ycenter ;1-20=-19
AddPathBox(xstart-1,ystart-1,2,2)
VectorSourceColor($FFFF0000)
StrokePath(1)
AddPathBox(xcenter-1,ycenter-1,2,2)
VectorSourceColor($FF00FF00)
StrokePath(1)
AddPathBox(xend-1,yend-1,2,2)
VectorSourceColor($FF0000FF)
StrokePath(1)
mb=Sqr(Pow(i2,2)+Pow(j2,2));radius2 mb=sqr(36+36)=19.92 mb=Sqr(Pow(stop\x-m\x,2)+Pow(stop\y-m\y,2))
If Abs(ma-mb)>#Epsilon ;if end and start differs more than 0.001 oops
Debug "Oops."
EndIf
wa=ATan2(i,j); atan2(-19,-5)=-2.8842689386
wa=Degree(wa)
wb=ATan2(i2,j2);atan2(6,-19)= -1.2649174554 wb=Angle(m,stop):Debug "eind="+wb
wb=Degree(wb)
Debug "start="+wa+" end="+wb
VectorSourceColor(#Draw100|color)
If direction
AddPathCircle(xcenter,ycenter,ma,wa,wb); AddPathCircle(m\x,m\y,ma,wa,wb) ;x,y center,straal,start ,end
Else
AddPathCircle(xcenter,ycenter,ma,wb,wa); AddPathCircle(m\x,m\y,ma,wb,wa)
EndIf
StrokePath(2)
If wa<0 :wa=wa+360:EndIf
If wb<0 :wb=wb+360:EndIf ;make positive
Debug "start=" +wa+" end="+wb
EndProcedure
;----------------------------------------------------------
Procedure Draw()
StartVectorDrawing(CanvasVectorOutput(0))
TranslateCoordinates(x_off,y_off)
ScaleCoordinates(zoom,zoom)
Arc(0,#Blue)
;Arc(1,#Cyan)
StopVectorDrawing()
EndProcedure
;-----------------------------------------------------------
OpenWindow(0,0,0,1500,1000,"")
CanvasGadget(0,0,0,1500,1000)
Draw()
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow
End
EndSelect
ForEver
Re: drawin arcs
Michael,
the arc was in the wrong quadrant.
I try FlipCoordinatesY(90) ,now it is ok.
You add
TranslateCoordinates(x_off,y_off)
ScaleCoordinates(zoom,zoom)
How can I get the drawing in the middle of the screen, because at zoom> 5 the drawing is going outside the canvas?
I still have a lot to learn!
Many thanks for your support.
the arc was in the wrong quadrant.
I try FlipCoordinatesY(90) ,now it is ok.
You add
TranslateCoordinates(x_off,y_off)
ScaleCoordinates(zoom,zoom)
How can I get the drawing in the middle of the screen, because at zoom> 5 the drawing is going outside the canvas?
I still have a lot to learn!
Many thanks for your support.