Search code examples
c#g-code

Get the centerpoint of an Arc - G-Code Conversion


Herro

Its the First Time I'm posting Here I'm New To C# But I'm Tying Something difficult

In the Illustration You Will Find Coordinates Of a Arc All Points Referenced From (0,0) The X Axis is Horizontal The Z Axis is Vertical

https://i.sstatic.net/ycmdi.png

Input Variables:

Xo,Zo =(529.819,343.509)
Xn,Zn =(529.26,343.678)
R(Radius) =(9.2)

I Need The Coordinates of I,K(Centrer Point,Referenced to 0,0)

The Answer to I,K is (I532.2,K352.396) But I want to know how to calculate this

This Is Going to Be uses in G code Conversion Eg:

N8(3)X529.819Z343.509$
N9(4)X529.26Z343.678R9.2C0$

To

N8(3)X529.819Z343.509$
N9(4)X529.26Z343.678I532.2K352.396$

(C0 & C1 is CW & CCW)


Solution

  • A copy/paste of some VB6 code I wrote ages ago, it runs on a lot of machines every day. It works by rotating the coordinate system by the angle between the two points, thus greatly simplifying the math. Tangent() returns the angle, Rotate() rotates a point, Sqr() is Math.Sqrt() in C#:

      '--- Compute arc center from radius
      Dim tang#, w#
      tang = co1.Tangent(co2)
      co2.Rotate co1, -tang
      center.X = (co1.X + co2.X) / 2
      center.Y = 0
      w = center.X - co1.X
      If Abs(mModal.RWord) < w Then
        '--- R-word too small
        If mModal.ThrowErr And w - Abs(mModal.RWord) > 0.00
          Err.Raise 911, , "R-word too small"
        End If
      Else
        center.Y = -Sqr(mModal.RWord * mModal.RWord - w * w
      End If
      '--- Choose out of the 4 possible arcs
      If Not cw Then center.Y = -center.Y
      If mModal.RWord < 0 Then center.Y = -center.Y
      center.Y = center.Y + co1.Y
      center.Rotate co1, tang
      co2.Rotate co1, tang
      GetArcCenter = center