Trigonometry trick

Started by
10 comments, last by boubi 12 years, 10 months ago
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 :
circlep.png
Advertisement
unledcsa.png

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)
Edge cases will show your design flaws in your code!
Visit my site
Visit my FaceBook
Visit my github
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
If your really concerned, theta can be one of 360 values in degrees, so make a lookup table , then it would be simply tanLookup[theta] * (x - x0) , which isn't much computation.
Edge cases will show your design flaws in your code!
Visit my site
Visit my FaceBook
Visit my github

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


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.
Can you post your solution that uses the quadratic formula?

Can you post your solution that uses the quadratic formula?


Try to google : ray circle intersection 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.
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 :

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

Horizontal lenght

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

Full lenght of segment of intersection

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

I have tested it graphically with an application.

See u later !
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?
I trust exceptions about as far as I can throw them.

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?


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

This topic is closed to new replies.

Advertisement