How to center a rotated arc?

Find quick help here to get you started with Hollywood
Post Reply
amyren
Posts: 410
Joined: Thu May 02, 2019 11:53 am

How to center a rotated arc?

Post 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
User avatar
emeck
Posts: 191
Joined: Fri Apr 03, 2015 3:17 pm

Re: How to center a rotated arc?

Post by emeck »

If you are using layers, maybe using SetLayerAnchor() and RotateLayer() would be easier?
PowerBook 5.8 MorphOS 3.18
Mac Mini MorphOS 3.18
amyren
Posts: 410
Joined: Thu May 02, 2019 11:53 am

Re: How to center a rotated arc?

Post 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.
amyren
Posts: 410
Joined: Thu May 02, 2019 11:53 am

Re: How to center a rotated arc?

Post 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
Post Reply