Sign in to follow this  
boubi

Trigonometry trick

Recommended Posts

Hi community, i want to find the length in height of a 2D intersection between Circle and Ray , i know how to do it with quadratic equation but i want to find a way of doing it with less operations :

So here is the challenge : i have in input parameter the height of the ray and the cosine of angle with horizontal axis let's say cos teta.
I post a picture in order to see the problem i wanted to solve, i tried trigonometric identities but i can't figure out with one valid because the ray is offseted by the height...maybe there is no solution, but i don't think so..
Thanx for your help...

here is the pic :
[img]http://img842.imageshack.us/img842/2734/circlep.png[/img]

Share this post


Link to post
Share on other sites
[img]http://imageshack.us/m/854/4980/unledcsa.png[/img]

You want to find L.

Note the following :

a = 90 - theta
180 = 90 + a + b
180 - 90 - a = b
b = 90 - a;
b = 90 - (90 - theta) = theta


sin(b) = L / h
L = sin(b) * h

cos(theta) = (x-x0) / h
h = (x-x0) / cos(theta)
hence L = sin(b) * (x - x0 ) / cos(theta)


where b = theta, so

L = tan(theta) * (x - x0)

Share this post


Link to post
Share on other sites
oh sorry i omitt that i don't want to have teta as input... only the cosine , sorry
i will have tons of calls of this so i want to avoid using arc cosine functions...
Thanks for your help

Share this post


Link to post
Share on other sites
If your really concerned, theta can be one of 360 values in degrees, so make a lookup table , then it would be simply [i] tanLookup[theta] * (x - x0) [/i], which isn't much computation.

Share this post


Link to post
Share on other sites
[quote name='D.Chhetri' timestamp='1305682685' post='4812199']
If your really concerned, theta can be one of 360 values in degrees, so make a lookup table , then it would be simply [i] tanLookup[theta] * (x - x0) [/i], which isn't much computation.
[/quote]

I know of how to optimize software, but the goal of my post is the challenge of trying to solve this with trigonometry sorry...it's kinda a headache math puzzle game :)

Anyone is welcome , so let's go ! try to solve this if you are a player ...

Cheers.

Share this post


Link to post
Share on other sites
[quote name='quasar3d' timestamp='1305754216' post='4812743']
Can you post your solution that uses the quadratic formula?
[/quote]

Try to google : [b]ray circle intersection[/b] you will find answers to do this, sorry this is not the purpose of this topic, basically you just have to plug the ray parametric form into the equation of the circle or sphere if you want it in 3D, then you develop all the stuff and you will see appearing the quadratic equation At2 + Bt + C = 0 wich is really simple to solve.

Share this post


Link to post
Share on other sites
Hi, community i post the answer in case someone is interrested one day i have tons of tons of operations like that so that's why i wanted to save some cycle through smarter formulas.

I have found how to do it , and checked it in a unit test application :

Basically it's just applying the trigonometric identiy sin teta = sqrt(1-cos^2 teta) and rescale it by the circle wich is at center (x0,y0) and radius (R-y0).
therefore to know the value i searched is :

[u]Vertical length of the intersection segment with circle is given :[/u]
[b]sqrt(1-cos^2 teta)*(R-y0).[/b]

[u]Horizontal lenght[/u]

For horizontal distance : we need to apply a simple thales formula wich will give you :
[b](R-x0)*cos teta[/b]

[u]Full lenght of segment of intersection[/u]

simply apply pythagorean theorem :
[b]sqrt(1-cos^2 teta)*(R-y0) + [/b][b](R-x0)*cos teta[/b]

I have tested it graphically with an application.

See u later !

Share this post


Link to post
Share on other sites
A circle-line intersection is a quadratic operation so it is impossible to solve without using square roots or equivalent trigonometric constructs.

Is there any particular reason you are trying to avoid using the quadratic formula to solve a quadratic problem?

Share this post


Link to post
Share on other sites
[quote name='Storyyeller' timestamp='1305942407' post='4813720']
A circle-line intersection is a quadratic operation so it is impossible to solve without using square roots or equivalent trigonometric constructs.

Is there any particular reason you are trying to avoid using the quadratic formula to solve a quadratic problem?
[/quote]

I didn't explained me well sorry, but i only wanted to know the length of the segment making the intersection between ray from wich we have only in input altitude and cos teta, i suppose that i must intersect and limit myself to one quarter of the circle, that's what permitt me to avoid quadratic problems.

I do this because i'm generating a lookuptable for GPU caculcation, the lookup table is quite a bit intensive because it evaluates several integrals ... so that's why i'm looking a way to do things very simple and so fast.

The cos teta and altitude will be my indexes in this lookup table.

Thanks for all your interests...

Share this post


Link to post
Share on other sites
Fix ! a small error has been done on typo :

For horizontal distance : we need to apply a simple thales formula wich will give you :
[b](R-x0)*cos teta*0.5


[/b]

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this