Slight inaccuracy with Circle

Report any Hollywood bugs here
Post Reply
Bugala
Posts: 1399
Joined: Sun Feb 14, 2010 7:11 pm

Slight inaccuracy with Circle

Post by Bugala »

I just did bit of a test to basically try out collision detection with a circle, and it seems like there might be a small inaccuracy with a circle command (nothing critical)

Code: Select all

Circle(250, 250, 50, #WHITE)
cx = {310, 320, 330, 340, 350}
cy = {300, 310, 320, 330, 340}

For n=0 To 4
	Circle(cx[n]-1, cy[n]-1, 1, #WHITE)
	inside=False
	xpow=(cx[n]-300)
	ypow=(cy[n]-300)
	xpow=Pow(xpow, 2)
	ypow=Pow(ypow, 2)
	totalpow=xpow+ypow
	distance=Sqrt(totalpow)
	DebugPrint("distance: "..distance)
Next



WaitLeftMouse
If you try this out you can notice that one of the dots is exactly 50 distance away, which I would think should mean that it should appear exactly at the outlet of the circle. However, it seems to be one pixel off from its location.

If I change the number to at least 3:

Code: Select all

Circle(cx[n]-3, cy[n]-3, 3, #WHITE)
Then I'm not sure, but looks like the center might be at a right location.

This was tested on Hollywood 8 Win64.
User avatar
airsoftsoftwair
Posts: 5871
Joined: Fri Feb 12, 2010 2:33 pm
Location: Germany
Contact:

Re: Slight inaccuracy with Circle

Post by airsoftsoftwair »

That's normal behaviour. Circles are drawn using lines so it's not perfectly round. For a better algorithm, draw circles as real Bézier splines using the vectorgraphics library. This can be done by setting ForcePathUse() to TRUE, i.e.

Code: Select all

ForcePathUse(True)

Circle(250, 250, 50, #WHITE)
cx = {310, 320, 330, 340, 350}
cy = {300, 310, 320, 330, 340}

For n=0 To 4
	Circle(cx[n]-1, cy[n]-1, 1, #WHITE)
	inside=False
	xpow=(cx[n]-300)
	ypow=(cy[n]-300)
	xpow=Pow(xpow, 2)
	ypow=Pow(ypow, 2)
	totalpow=xpow+ypow
	distance=Sqrt(totalpow)
	DebugPrint("distance: "..distance)
Next
Post Reply