[Module] DrawVectorEx - Module

Applications, Games, Tools, User libs and useful stuff coded in PureBasic
IdeasVacuum
Always Here
Always Here
Posts: 6425
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: [Module] DrawVectorEx - Module

Post by IdeasVacuum »

Hi Thorsten

Looks very interesting. The X1 to Y4 values represent the line ends right? Should they be in a specific order?
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
User avatar
Thorsten1867
Addict
Addict
Posts: 1366
Joined: Wed Aug 24, 2005 4:02 pm
Location: Germany

Re: [Module] DrawVectorEx - Module

Post by Thorsten1867 »

Line 1: P1(X1,Y1) -> P2(X2,Y2)
Line 2: P3(X3,Y3) -> P4(X4, Y4)
Arc: P2 -> P3
Last edited by Thorsten1867 on Sun Mar 15, 2020 12:10 am, edited 1 time in total.
Translated with http://www.DeepL.com/Translator

Download of PureBasic - Modules
Download of PureBasic - Programs

[Windows 11 x64] [PB V5.7x]
IdeasVacuum
Always Here
Always Here
Posts: 6425
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: [Module] DrawVectorEx - Module

Post 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
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
User avatar
Thorsten1867
Addict
Addict
Posts: 1366
Joined: Wed Aug 24, 2005 4:02 pm
Location: Germany

Re: [Module] DrawVectorEx - Module

Post by Thorsten1867 »

Image
Translated with http://www.DeepL.com/Translator

Download of PureBasic - Modules
Download of PureBasic - Programs

[Windows 11 x64] [PB V5.7x]
IdeasVacuum
Always Here
Always Here
Posts: 6425
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: [Module] DrawVectorEx - Module

Post 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.
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
IdeasVacuum
Always Here
Always Here
Posts: 6425
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: [Module] DrawVectorEx - Module

Post by IdeasVacuum »

:)

Image
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
IdeasVacuum
Always Here
Always Here
Posts: 6425
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: [Module] DrawVectorEx - Module

Post by IdeasVacuum »

Trying to work out the formula :mrgreen:

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:

Image
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
User avatar
Thorsten1867
Addict
Addict
Posts: 1366
Joined: Wed Aug 24, 2005 4:02 pm
Location: Germany

Re: [Module] DrawVectorEx - Module

Post by Thorsten1867 »

Image

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.
Last edited by Thorsten1867 on Sun Mar 15, 2020 12:14 am, edited 4 times in total.
Translated with http://www.DeepL.com/Translator

Download of PureBasic - Modules
Download of PureBasic - Programs

[Windows 11 x64] [PB V5.7x]
User avatar
Thorsten1867
Addict
Addict
Posts: 1366
Joined: Wed Aug 24, 2005 4:02 pm
Location: Germany

Re: [Module] DrawVectorEx - Module

Post 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. :?
Last edited by Thorsten1867 on Sun Mar 15, 2020 12:15 am, edited 2 times in total.
Translated with http://www.DeepL.com/Translator

Download of PureBasic - Modules
Download of PureBasic - Programs

[Windows 11 x64] [PB V5.7x]
User avatar
Thorsten1867
Addict
Addict
Posts: 1366
Joined: Wed Aug 24, 2005 4:02 pm
Location: Germany

Re: [Module] DrawVectorEx - Module

Post by Thorsten1867 »

Update:
  • TangentsArc_()
  • LinesArc_()
Translated with http://www.DeepL.com/Translator

Download of PureBasic - Modules
Download of PureBasic - Programs

[Windows 11 x64] [PB V5.7x]
IdeasVacuum
Always Here
Always Here
Posts: 6425
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: [Module] DrawVectorEx - Module

Post by IdeasVacuum »

... lost in translation I think, sorry. :oops:

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
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
User avatar
Thorsten1867
Addict
Addict
Posts: 1366
Joined: Wed Aug 24, 2005 4:02 pm
Location: Germany

Re: [Module] DrawVectorEx - Module

Post 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!).
Translated with http://www.DeepL.com/Translator

Download of PureBasic - Modules
Download of PureBasic - Programs

[Windows 11 x64] [PB V5.7x]
IdeasVacuum
Always Here
Always Here
Posts: 6425
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: [Module] DrawVectorEx - Module

Post by IdeasVacuum »

...thanks Thorsten - I overlooked the need for 32bit colour.
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
User avatar
Thorsten1867
Addict
Addict
Posts: 1366
Joined: Wed Aug 24, 2005 4:02 pm
Location: Germany

Re: [Module] DrawVectorEx - Module

Post by Thorsten1867 »

Update: Automatic color conversion
Translated with http://www.DeepL.com/Translator

Download of PureBasic - Modules
Download of PureBasic - Programs

[Windows 11 x64] [PB V5.7x]
IdeasVacuum
Always Here
Always Here
Posts: 6425
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: [Module] DrawVectorEx - Module

Post by IdeasVacuum »

Automatic color conversion
Works great :D
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
Post Reply