Hello Guest it is January 26, 2020, 10:56:47 PM

Author Topic: macro problem  (Read 2717 times)

0 Members and 1 Guest are viewing this topic.

macro problem
« on: May 03, 2009, 11:52:42 AM »
Hello .
This program was written in vb , I want to run the program on macro from the Gcode.
the mach3 editor ,does not get it .
I really thanked those who could help repair program.






Function FindIntersection(px11 As Single, py11 As Single, px12 As Single, py12 As Single, px21 As Single, py21 As Single, px22 As Single, py22 As Single) As String
Dim dx1 As Single
Dim dy1 As Single
Dim dx2 As Single
Dim dy2 As Single
Dim t1 As Single
Dim t2 As Single
Dim nUl As Single

On Error GoTo err


   
   
    dx1 = px12 - px11                 ' calulates dx,dy for each point
    dy1 = py12 - py11
    dx2 = px22 - px21
    dy2 = py22 - py21

    nUl = (dy1 * dx2 - dx1 * dy2)
    t1 = ((px11 - px21) * dy2 + (py21 - py11) * dx2) / nUl
    t2 = ((px21 - px11) * dy1 + (py11 - py21) * dx1) / -nUl

    nInter_x = px11 + dx1 * t1    'X point
    nInter_y = py11 + dy1 * t1    'Y point
   
 
    FindIntersection = Round(inter_x, 2) & "," & Round(inter_y, 2)
err:
    If err.Number = 11 Then Label1.Caption = "parallel lines"
       
End Function
« Last Edit: May 03, 2009, 11:55:57 AM by eyalyossef »

vmax549

*
Re: macro problem
« Reply #1 on: May 07, 2009, 09:35:32 AM »
HIYA Eyal,  You were close(;-)to getting it running. I just made a couple of changes and it runs.




Function FindIntersection(px11 As Single, py11 As Single, px12 As Single, py12 As Single, px21 As Single, py21 As Single, px22 As Single, py22 As Single) As String    ( SHOULD BE all one line)


Dim dx1 As Single
Dim dy1 As Single
Dim dx2 As Single
Dim dy2 As Single
Dim t1 As Single
Dim t2 As Single
Dim nUl As Single

On Error GoTo N2

   
    dx1 = px12 - px11                 ' calulates dx,dy for each point
    dy1 = py12 - py11
    dx2 = px22 - px21
    dy2 = py22 - py21

    nUl = (dy1 * dx2 - dx1 * dy2)
    t1 = ((px11 - px21) * dy2 + (py21 - py11) * dx2) / nUl
    t2 = ((px21 - px11) * dy1 + (py11 - py21) * dx1) / -nUl

    nInter_x = px11 + dx1 * t1    'X point
    nInter_y = py11 + dy1 * t1    'Y point
   
 
    FindIntersection = Round(inter_x, 2) & "," & Round(inter_y, 2)

N2:
    If err.Number = 11 Then Message"parallel lines"
       
End






(;-) TP