Page 1 of 1

How to center a rotated arc?

Posted: Sun Jun 01, 2025 5:37 pm
by amyren
Is there an easy way to calculate the correct offset for the X and Y position of an Arc that is rotated?
I want it to be drawn so that the startposx and startposy always will be the center of the arc.
The code below will put it centered as long as the ratation is 0, but some trigonometry is probably required to get this result at any rotation.

Code: Select all

startposx = 320
startposy = 240
arcrot = 0
SetFillStyle(#FILLCOLOR)
xrad = 50
yrad = 80
For arcrot = 0 To 360
Cls	
Line(0, 240, 640, 240, #WHITE)
Line(320, 0, 320, 480, #WHITE)
Arc(startposx-xrad, startposy-yrad, xrad, yrad, 90, 270, #RED, {Rotate = arcrot})
Wait(1)
Next
WaitLeftMouse

Re: How to center a rotated arc?

Posted: Sun Jun 01, 2025 7:07 pm
by emeck
If you are using layers, maybe using SetLayerAnchor() and RotateLayer() would be easier?

Re: How to center a rotated arc?

Posted: Mon Jun 02, 2025 9:33 am
by amyren
emeck wrote: Sun Jun 01, 2025 7:07 pm If you are using layers, maybe using SetLayerAnchor() and RotateLayer() would be easier?
I guess that might be easier, but I do not use layers in this program. There are sprites in the program as well which complicate the use of layers.
I was hoping it was possible to have a formula that could calculate the offset.

Re: How to center a rotated arc?

Posted: Tue Jun 03, 2025 9:57 pm
by amyren
This seem to solve it

Code: Select all

SetFillStyle(#FILLCOLOR)
startx = 320
starty = 240
xrad = 50
yrad = 120
For arcrot = 0 To 360 Step 1
	Cls
	Line(0, 240, 640, 240, #WHITE)
	Line(320, 0, 320, 480, #WHITE)
	Rad = arcrot * #PI / 180
	x = startx - (xrad * Cos(Rad)) - (yrad * Sin(Rad))
	y = starty + (xrad * Sin(Rad)) - (yrad * Cos(Rad))
	Arc(x, y, xrad, yrad, 0, 270, #RED, {Rotate = arcrot})
	Wait(1)
Next
WaitLeftMouse