calculate center of arc

Just starting out? Need help? Post your questions and find answers here.
ludoke
Enthusiast
Enthusiast
Posts: 153
Joined: Fri Jul 08, 2016 5:35 pm
Location: Essen (Belgium)

calculate center of arc

Post by ludoke »

I've been trying for a while to find a way to calculate the center of an arc, but I can't get out, maybe there's a mathematical genius.
I have the startpoint X1,Y1 the endpoint X2,Y2 and the radius R ,I need the centerpoint XC,YC .
The arc can be in one or more quadrants.
User avatar
STARGÅTE
Addict
Addict
Posts: 2090
Joined: Thu Jan 10, 2008 1:30 pm
Location: Germany, Glienicke
Contact:

Re: calculate center of arc

Post by STARGÅTE »

As you probably can imagine, there are two solution for such a center point:
https://stackoverflow.com/questions/429 ... orrespondi
PB 6.01 ― Win 10, 21H2 ― Ryzen 9 3900X, 32 GB ― NVIDIA GeForce RTX 3080 ― Vivaldi 6.0 ― www.unionbytes.de
Lizard - Script language for symbolic calculations and moreTypeface - Sprite-based font include/module
infratec
Always Here
Always Here
Posts: 6883
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: calculate center of arc

Post by infratec »

In PB:

Code: Select all

EnableExplicit


Procedure.i Circle2PtsRad(x1.i, y1.i, x2.i, y2.i, r.i, *middle.Point)
  
  Protected Result.i, d2.d, det.d, h.d
  
  
  d2 = (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)
  det = r * r / d2 - 0.25
  
  If det >= 0.0
    h = Sqr(det)
    *middle\x = (x1 + x2) * 0.5 + (y1 - y2) * h
    *middle\y = (y1 + y2) * 0.5 + (x2 - x1) * h
    Result = #True
  EndIf
  
  ProcedureReturn Result
  
EndProcedure


Define Middle.Point

#x1 = 80
#y1 = 30

#x2 = 130
#y2 = 30

#r = 80

If OpenWindow(0, 0, 0, 200, 200, "CircleCalc", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  If CreateImage(0, 200, 200) And StartDrawing(ImageOutput(0))
    
    If Circle2PtsRad(#x1, #y1, #x2, #y2, #r, @Middle)
      Debug Str(Middle\x) + " / " + Str(Middle\y)
      
      Circle(Middle\x, Middle\y, #r, #Blue)
      
      Plot(#x1, #y1, #Red)
      Plot(#x2, #y2, #Red)
      
    Else
      Debug "Not possible"
    EndIf
    
    StopDrawing() 
    ImageGadget(0, 0, 0, 200, 200, ImageID(0))
  EndIf
  
  Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf
IdeasVacuum
Always Here
Always Here
Posts: 6425
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: calculate center of arc

Post by IdeasVacuum »

.... We had a lot of trigonometry examples in the Games Math section - but that seems to have disappeared when the new forum was introduced?
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
Olli
Addict
Addict
Posts: 1071
Joined: Wed May 27, 2020 12:26 pm

Re: calculate center of arc

Post by Olli »

@ludoke

I agree with STARGÅTE : there are 2 points which match to the initial characteristics.

But what it misses is only a binary status. More accurately, in geometry, what it misses is an orientation.

The tip of infratec consists in deciding, on computing, the characteristics (points positions) have an order.

Point1, point2, etc...

While, in math, this "communicating flow order" does not exist :

PointA, PointB, etc... : while we do not add features in math, every points (or generally, every objects) can be exchangeable (PointA should welly be called PointB, etc...). That is the reason, in math, it misses an information, which is here binary (2 stats). Information which did not seem disturb infratec.
IdeasVacuum wrote:.... We had a lot of trigonometry examples in the Games Math section - but that seems to have disappeared when the new forum was introduced?
we can try to ask this in the bug report to understand...

Math remark for ludoke : I was myself on the point that from 2 two points and from one radius value, as you asked, there were an infinity of results, because there are several manner to describe an arc :

- circular arc
- elliptic arc
- rotated elliptic arc

I was far to answer you...
ludoke
Enthusiast
Enthusiast
Posts: 153
Joined: Fri Jul 08, 2016 5:35 pm
Location: Essen (Belgium)

Re: calculate center of arc

Post by ludoke »

infratec thanks,I know that there are 2 solutions.
Now I can try to find the start and end angle of the arc.
Maybe I can ask you this, too.
Post Reply