Trig Problem

Started by
2 comments, last by grhodes_at_work 15 years, 5 months ago
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?
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?
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 = - C // center of circle projected &#111;nto line, back in "circle space" at the original origin</tt><br><br>We then check if the line is too far away from the circle to intersect. This is true if <tt>(P.P) &gt; r<sup>2</sup></tt> (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:<br><br><tt>d = &#8730;[ r<sup>2</sup> - (P.P) ] // note that if we didn't perform the previous check, the value inside the radical could be negative!</tt><br><br>The points of intersection are then:<br><br><tt>I = P ± Unit(S) * d // Unit() is a function that normalizes a vector</tt><br><br>Note that if 'd' is zero, the line is tangent to the circle and in reality there's &#111;nly &#111;ne intersection point.<br><br>Once you have the intersection points, you can use <tt>atan2</tt> to determine the angle (or an equivalent function if you're not using the C++ math library). Set that angle equal to <tt>S + W*dt</tt> and you can easily solve for 'dt' from there.
ninjackal,

Please provide some context for your question. Why are you trying to solve this problem?

Graham Rhodes Moderator, Math & Physics forum @ gamedev.net

This topic is closed to new replies.

Advertisement