# 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..

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

##### 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 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...

##### 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 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 on other sites
[quote name='quasar3d' timestamp='1305754216' post='4812743']
[/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 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 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 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.

##### 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 on other sites
Again me : it works only if point inside circle... too bad...
the question is still open for point outside circle....

## Create an account

Register a new account

• ### Forum Statistics

• Total Topics
628377
• Total Posts
2982324

• 10
• 9
• 14
• 24
• 11