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.
calculate center of arc
Re: calculate center of arc
As you probably can imagine, there are two solution for such a center point:
https://stackoverflow.com/questions/429 ... orrespondi
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 more ― Typeface - Sprite-based font include/module
Lizard - Script language for symbolic calculations and more ― Typeface - Sprite-based font include/module
Re: calculate center of arc
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
-
- Always Here
- Posts: 6425
- Joined: Fri Oct 23, 2009 2:33 am
- Location: Wales, UK
- Contact:
Re: calculate center of arc
.... 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.
If it sounds simple, you have not grasped the complexity.
Re: calculate center of arc
@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.
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...
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.
we can try to ask this in the bug report to understand...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?
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...
Re: calculate center of arc
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.
Now I can try to find the start and end angle of the arc.
Maybe I can ask you this, too.