POV-Ray : Newsgroups : povray.off-topic : Bounding circle intersection Server Time
4 Sep 2024 23:22:19 EDT (-0400)
  Bounding circle intersection (Message 21 to 30 of 43)  
<<< Previous 10 Messages Goto Latest 10 Messages Next 10 Messages >>>
From: Invisible
Subject: Re: Bounding circle intersection
Date: 11 Dec 2009 04:08:31
Message: <4b220c0f$1@news.povray.org>
>>   Suppose that the most significant non-zero digit of x is in the 2^n 
>> place. Let y = x / 2^(n/2). Now Sqrt(x) is approximately x / y.
> 
> Is there a way to quickly get n for a given number?

If you don't mind depending on a specific floating-point 
representation... sure. Just find out which bits of the number contain 
the exponent. (For example, for a double-precision IEEE float, the 
bitmask is 0x7FFF000000000000, and you then shift out those zeros and 
subtract 0x3FFF to get the real value.)

That's what makes this so efficient. You just need the exponent field 
from the float value, so no need to calculate anything. (Indeed, as an 
even rougher approximation, just halve the exponent...)


Post a reply to this message

From: Invisible
Subject: Re: Bounding circle intersection
Date: 11 Dec 2009 04:09:45
Message: <4b220c59$1@news.povray.org>
scott wrote:

> So let me understand this, you are constructing two circles, one around 
> the line and one around the triangle, then seeing the circles intersect, 
> and if they do proceeding to check if the line actually intersects the 
> triangle?
> 
> Wouldn't it be faster to just directly check the line against the triangle?

It would.

Now, if the circle encloses a few *thousand* triangles, it's probably 
way, way faster to check the circle first...


Post a reply to this message

From: Slime
Subject: Re: Bounding circle intersection
Date: 11 Dec 2009 05:45:53
Message: <4b2222e1$1@news.povray.org>
> So let me understand this, you are constructing two circles, one around 
> the line and one around the triangle, then seeing the circles intersect, 
> and if they do proceeding to check if the line actually intersects the 
> triangle?

Well, the one around the triangle is precomputed. Otherwise, yes.

> Wouldn't it be faster to just directly check the line against the 
> triangle?

Honestly, I don't know. I'm not sure my code for the triangle-line check is 
very good. =)

As far as I can tell, to check for an intersection between a triangle and a 
line segment, you need to check that one of the triangle's vertices is on an 
opposite side of the line from the other two, and then check that both of 
the line segment's endpoints are on opposite sides of at least one of the 
triangle's edges, or that both of them are inside the triangle.

I did most of these checks with cross products, and then found I had some 
precision problems in some cases, and the code got more complicated when I 
tried to avoid them. Since intersections are rare, I figured a bounding 
check would be the easiest way to improve performance.

 - Slime
 [ http://www.slimeland.com/ ]


Post a reply to this message

From: Invisible
Subject: Re: Bounding circle intersection
Date: 11 Dec 2009 05:54:20
Message: <4b2224dc$1@news.povray.org>
>> Wouldn't it be faster to just directly check the line against the 
>> triangle?
> 
> Honestly, I don't know. I'm not sure my code for the triangle-line check is 
> very good. =)
> 
> As far as I can tell, to check for an intersection between a triangle and a 
> line segment, you need to check that one of the triangle's vertices is on an 
> opposite side of the line from the other two, and then check that both of 
> the line segment's endpoints are on opposite sides of at least one of the 
> triangle's edges, or that both of them are inside the triangle.
> 
> I did most of these checks with cross products, and then found I had some 
> precision problems in some cases, and the code got more complicated when I 
> tried to avoid them. Since intersections are rare, I figured a bounding 
> check would be the easiest way to improve performance.

Er... yeah, that's not terribly good. ;-)

Do a quick google for "ray triangle intersection". There are several 
methods for doing this kind of thing, some of them highly optimised.


Post a reply to this message

From: Slime
Subject: Re: Bounding circle intersection
Date: 11 Dec 2009 06:28:25
Message: <4b222cd9@news.povray.org>
> Er... yeah, that's not terribly good. ;-)
>
> Do a quick google for "ray triangle intersection". There are several 
> methods for doing this kind of thing, some of them highly optimised.

That tends to give results for a 3D problem, whereas my problem is 2D.

 - Slime
 [ http://www.slimeland.com/ ]


Post a reply to this message

From: Invisible
Subject: Re: Bounding circle intersection
Date: 11 Dec 2009 06:46:53
Message: <4b22312d@news.povray.org>
Slime wrote:
>> Er... yeah, that's not terribly good. ;-)
>>
>> Do a quick google for "ray triangle intersection". There are several 
>> methods for doing this kind of thing, some of them highly optimised.
> 
> That tends to give results for a 3D problem, whereas my problem is 2D.

Many of the methods work for 2D as well though.

But now I'm curious... the cross product is only defined for 3D vectors, 
but you said you used a lot of cross products?


Post a reply to this message

From: scott
Subject: Re: Bounding circle intersection
Date: 11 Dec 2009 07:14:19
Message: <4b22379b$1@news.povray.org>
> But now I'm curious... the cross product is only defined for 3D vectors, 
> but you said you used a lot of cross products?

Treat your 2D working area as a plane in 3D space (with Z coordinate zero if 
you like), then you can do cross products, and checking whether the result 
points "in to" the plane or "out of" the plane can be pretty useful (eg to 
find out which side of a line a point is on).


Post a reply to this message

From: Invisible
Subject: Re: Bounding circle intersection
Date: 11 Dec 2009 07:40:19
Message: <4b223db3@news.povray.org>
scott wrote:
>> But now I'm curious... the cross product is only defined for 3D 
>> vectors, but you said you used a lot of cross products?
> 
> Treat your 2D working area as a plane in 3D space (with Z coordinate 
> zero if you like), then you can do cross products, and checking whether 
> the result points "in to" the plane or "out of" the plane can be pretty 
> useful (eg to find out which side of a line a point is on).

Oh, right.

...or you could just take the dot product instead, which requires only 2 
multiplies and one addition as opposed to four multiplies and two 
subtractions...


Post a reply to this message

From: scott
Subject: Re: Bounding circle intersection
Date: 11 Dec 2009 08:23:10
Message: <4b2247be$1@news.povray.org>
> ...or you could just take the dot product instead, which requires only 2 
> multiplies and one addition as opposed to four multiplies and two 
> subtractions...

How is that useful?


Post a reply to this message

From: Invisible
Subject: Re: Bounding circle intersection
Date: 11 Dec 2009 08:24:15
Message: <4b2247ff@news.povray.org>
scott wrote:
>> ...or you could just take the dot product instead, which requires only 
>> 2 multiplies and one addition as opposed to four multiplies and two 
>> subtractions...
> 
> How is that useful?

Because you can use it to determine which side of the line a point is on?


Post a reply to this message

<<< Previous 10 Messages Goto Latest 10 Messages Next 10 Messages >>>

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.