Jump to content
  • Advertisement
Sign in to follow this  
ninjackal

Trig Problem

This topic is 3559 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Given the equation of a line: X = X0 + Mx*k Y = Y0 + My*k where ( X0, Y0 ) is a point on the line and ( Mx, My ) is its' slope and k is a scalar, and given the path of a point orbiting about the origin: X = r*cos( S + W*dt ) Y = r*sin( S + W*dt ) where r is the distance of the point from the origin, S is the starting angle of the point, W is its' angular velocity as it orbits about the origin, and dt is the change in time In trying to solve for dt I get: X0 + Mx*k = r*cos(S + W*dt) k = (r*cos(S + W*dt) - X0)/Mx Y0 + My*k = r*sin(S + W*dt) k = (r*sin(S + W*dt) - Y0)/My and so, (r*cos(S + W*dt) - X0)/Mx = (r*sin(S + W*dt) - Y0)/My The value of every variable is known except for dt. Is there any way to determine the values of dt for which this equation is true?

Share this post


Link to post
Share on other sites
Advertisement
From what I can see, your problem ultimately boils down to finding the intersection point(s) of an arbitrary line and a circle of radius r centered at the origin. dt is nothing more than an angular parameter specifying a point on the circle in polar coordinates.

Maybe someone else here does, but I'm not sure of any easy way of doing this or of solving your particular equation. I hate to just drop a link, but have you looked at this MathWorld article which gives some equations?

Share this post


Link to post
Share on other sites
Like nilkn said, it looks to me like it's primarily a circle-line intersection problem.

The first step is to project the circle's center onto the line. Since the circle is at the origin, this boils down to:

C = (-X0,-Y0) // center of the circle in "line space"
S = (Mx,My) // slope of the line
P = [S * (C.S)/(S.S)] - C // center of circle projected onto line, back in "circle space" at the original origin


We then check if the line is too far away from the circle to intersect. This is true if (P.P) > r2 (the squared distance of the projected point from the center of the circle is greater than the squared radius of the circle). Otherwise, we can calculate the half-length of the chord created by the intersection using this:

d = √[ r2 - (P.P) ] // note that if we didn't perform the previous check, the value inside the radical could be negative!

The points of intersection are then:

I = P ± Unit(S) * d // Unit() is a function that normalizes a vector

Note that if 'd' is zero, the line is tangent to the circle and in reality there's only one intersection point.

Once you have the intersection points, you can use atan2 to determine the angle (or an equivalent function if you're not using the C++ math library). Set that angle equal to S + W*dt and you can easily solve for 'dt' from there.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!