Page 2 of 3
Re: [Module] DrawVectorEx - Module
Posted: Sat Mar 14, 2020 7:03 pm
by IdeasVacuum
Hi Thorsten
Looks very interesting. The X1 to Y4 values represent the line ends right? Should they be in a specific order?
Re: [Module] DrawVectorEx - Module
Posted: Sat Mar 14, 2020 7:23 pm
by Thorsten1867
Line 1: P1(X1,Y1) -> P2(X2,Y2)
Line 2: P3(X3,Y3) -> P4(X4, Y4)
Arc: P2 -> P3
Re: [Module] DrawVectorEx - Module
Posted: Sat Mar 14, 2020 8:10 pm
by IdeasVacuum
OK - there are a number of potential tangencies for a given corner, so the arc radius should be an input too.
Code: Select all
Enumeration
#MainWin
#CanvasGdt
#BtnDraw
EndEnumeration
XIncludeFile "D:\PROJECTS\PURE BASIC\DRAW VECTOR X\DrawVectorExModule.pbi"
Procedure MainWin()
;#-----------------
If OpenWindow(#MainWin, 0, 0, 600, 440, "Tangent Arc", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
ButtonGadget(#BtnDraw, 4, 4, 100, 30, "Draw")
CanvasGadget(#CanvasGdt, 4, 44, 592, 392)
EndIf
EndProcedure
Procedure DrawFillet()
;#--------------------
If Draw::StartVector_(#CanvasGdt, Draw::#Canvas)
Draw::SetStroke_(2)
Draw::LineXY_(73, 162, 193, 48, $010303, Draw::#DPI)
Draw::LineXY_(360, 141, 193, 48, $010303, Draw::#DPI)
Draw::TangentsArc_(73, 162, 193, 48, 360, 141, 193, 48, $FF0303, Draw::#DPI)
Draw::StopVector_()
EndIf
EndProcedure
Procedure WaitLoop()
;#------------------
Protected iQuit.i = #False
Repeat
Select WaitWindowEvent(1)
Case #PB_Event_CloseWindow
Select EventWindow()
Case #MainWin: iQuit = #True
EndSelect
Case #PB_Event_Gadget
Select EventGadget()
Case #BtnDraw: DrawFillet()
EndSelect
EndSelect
Until iQuit = #True
EndProcedure
MainWin()
WaitLoop()
End
Re: [Module] DrawVectorEx - Module
Posted: Sat Mar 14, 2020 8:17 pm
by Thorsten1867
Re: [Module] DrawVectorEx - Module
Posted: Sat Mar 14, 2020 8:24 pm
by IdeasVacuum
...by the way Thorsten, I notice that your procedures expect integer dimensions. According to the Help Docs, any unit of measure can be used, so in theory we can input doubles.
Re: [Module] DrawVectorEx - Module
Posted: Sat Mar 14, 2020 8:39 pm
by IdeasVacuum
Re: [Module] DrawVectorEx - Module
Posted: Sat Mar 14, 2020 9:16 pm
by IdeasVacuum
Trying to work out the formula
If the angle between the two lines is 90deg (@ X2 X3) then the distance to the points of tangency is the radius of the arc:

Re: [Module] DrawVectorEx - Module
Posted: Sat Mar 14, 2020 10:04 pm
by Thorsten1867
Look at the picture. (X2 <> X3)
The blue line has the coordinates X1, Y1 and X2,Y2.
The green line has X3,Y3 and X4,Y4.
The red arc is calculated.
Re: [Module] DrawVectorEx - Module
Posted: Sat Mar 14, 2020 10:28 pm
by Thorsten1867
Code: Select all
Enumeration
#MainWin
#CanvasGdt
#BtnDraw
EndEnumeration
XIncludeFile "DrawVectorExModule.pbi"
Procedure MainWin()
If OpenWindow(#MainWin, 0, 0, 600, 440, "Tangent Arc", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
ButtonGadget(#BtnDraw, 4, 4, 100, 30, "Draw")
CanvasGadget(#CanvasGdt, 4, 44, 592, 392)
EndIf
EndProcedure
Procedure DrawFillet()
X1.i = 72
Y1.i = 162
X2.i = 193
Y2.i = 48
X3.i = 360
Y3.i = 141
Radius.i = 45
If StartVectorDrawing(CanvasVectorOutput(#CanvasGdt))
MovePathCursor(X1, Y1)
AddPathArc(X2, Y2, X3, Y3, Radius)
AddPathLine(X3, Y3)
VectorSourceColor($FF0000FF)
StrokePath(2)
StopVectorDrawing()
EndIf
EndProcedure
Procedure WaitLoop()
Protected iQuit.i = #False
Repeat
Select WaitWindowEvent(1)
Case #PB_Event_CloseWindow
Select EventWindow()
Case #MainWin
iQuit = #True
EndSelect
Case #PB_Event_Gadget
Select EventGadget()
Case #BtnDraw: DrawFillet()
EndSelect
EndSelect
Until iQuit = #True
EndProcedure
MainWin()
WaitLoop()
End[i][/i]
If you mean this, I could have saved myself a lot of work since this function is already available in the vector library.
But this has nothing to do with the image and the link you gave me.

Re: [Module] DrawVectorEx - Module
Posted: Sat Mar 14, 2020 10:41 pm
by Thorsten1867
Update:
- TangentsArc_()
- LinesArc_()
Re: [Module] DrawVectorEx - Module
Posted: Sun Mar 15, 2020 12:13 am
by IdeasVacuum
... lost in translation I think, sorry.
The Vector library itself does not have a Fillet Arc where two
existing lines initially make a sharp corner and then later that corner can be rounded, which is my goal - the shape could be irregular with several sharp corners and later the User may wish to round-off (fillet) some of them. It's the most common way (in my view, most sensible way) that drawing packages deal with the corner arc requirement.
How does your new function LinesArc work?
Code: Select all
Procedure DrawFillet()
;#--------------------
If Draw::StartVector_(#CanvasGdt, Draw::#Canvas)
Draw::Font_(FontID(#Font))
Draw::SetStroke_(2)
;Draw::Text_(62, 164, "X1 Y1", $1313EB, #False, Draw::#DPI)
;Draw::Text_(170, 28, "X2 Y2", $1313EB, #False, Draw::#DPI)
;X1 Y1 X2 Y2
;Draw::LineXY_(73, 162, 193, 48, $010303, Draw::#DPI)
;Draw::Text_(358, 142, "X3 Y3", $1313EB, #False, Draw::#DPI)
;X2 Y2 X3 Y3
;Draw::LineXY_(193, 48, 360, 141, $010303, Draw::#DPI)
;X1 Y1 X2 Y2 X3 Y3 Rad Color Flags
Draw::LinesArc_(73, 162, 193, 48, 360, 141, 21, $FF0303, Draw::#DPI)
Draw::StopVector_()
EndIf
EndProcedure
Re: [Module] DrawVectorEx - Module
Posted: Sun Mar 15, 2020 12:25 am
by Thorsten1867
Code: Select all
Procedure DrawFillet()
X1.i = 72
Y1.i = 162
X2.i = 193
Y2.i = 48
X3.i = 360
Y3.i = 141
Radius.i = 60
If Draw::StartVector_(#CanvasGdt, Draw::#Canvas)
Draw::SetStroke_(2)
Draw::LinesArc_(X1, Y1, X2, Y2, X3, Y2, Radius, $FF008000, Draw::#DPI)
Draw::StopVector_()
EndIf
EndProcedure
You must use a valid color (Alpha!).
Re: [Module] DrawVectorEx - Module
Posted: Sun Mar 15, 2020 1:52 am
by IdeasVacuum
...thanks Thorsten - I overlooked the need for 32bit colour.
Re: [Module] DrawVectorEx - Module
Posted: Sun Mar 15, 2020 12:26 pm
by Thorsten1867
Update: Automatic color conversion
Re: [Module] DrawVectorEx - Module
Posted: Sun Mar 15, 2020 12:50 pm
by IdeasVacuum
Automatic color conversion
Works great
