Having Math Problem...
Hi guys,
I''m stuck. Here is what I''m trying to solve:
(the Ps are Points in 2D)
(Pc-P) DOT (Pc-P) = R^2
I know Pa,Pb,Pc and R so I use the parametric form like this:
(Pc-(Pa+T(Pb-Pa))) DOT (Pc-(Pa+T(Pb-Pa))) = R^2
That''s where I get stuck. I''m trying to get the T on one side but can''t figure out how. Do I treat it like regular algebra ?Do I have to split up the X and Y components ?
I''m trying to find a point on a line segment that is R distance from another point not on the line segment (I make the line segment so there can only be one point exactly R distance away, not two.)
Thank you.
July 06, 2003 06:01 PM
If you write it out, you''ll see that it turns into a quadratic equation, which can have zero, one, or two solutions.
All you need is the P. Don''t worry about the "t" or the "Pa/Pb" in the equation. Just write out the equation using x,y. This gives you an equation system, but you can add the constraints that Pa and Pb (the line segment) give you.
Once you write it all out, it''s simple algebra.
Another way of viewing the problem is finding the intersection between a circle and your line segment.
All you need is the P. Don''t worry about the "t" or the "Pa/Pb" in the equation. Just write out the equation using x,y. This gives you an equation system, but you can add the constraints that Pa and Pb (the line segment) give you.
Once you write it all out, it''s simple algebra.
Another way of viewing the problem is finding the intersection between a circle and your line segment.
it''s a line / sphere intersection test
line
-----
P is on line (O, D) if
(eq0) P = O + D.t
P is on sphere(C, r) if
(eq1) (P-C)^2 = r2
P is on both if
(eq2) ((O - C) + D.t)^2 = r2
(eq3) t^2 . (D^2) + t . (2 * ((O - C) .D)) + (O - C)^2 - r2 = 0
let
a = D^2
b = 2 * ((O - C) .D)
c = (O - C)^2 - r2
(eq3) is equivalent to a.t^2 + b.t + c = 0
=> Quadratic equation, 2 solutions
let d = b^2 - 4.a.c
solutions are
t1 = (- b - sqrt(d)) / 2.a
t2 = (- b + sqrt(d)) / 2.a
replace t in (eq0) by t1 and t2, and you get your points of intersections.
there are no intersection if d < 0, and only one if d = 0 (t1=t2=-b/2a)
that works both in 2D and 3D by the way.
line
-----
P is on line (O, D) if
(eq0) P = O + D.t
P is on sphere(C, r) if
(eq1) (P-C)^2 = r2
P is on both if
(eq2) ((O - C) + D.t)^2 = r2
(eq3) t^2 . (D^2) + t . (2 * ((O - C) .D)) + (O - C)^2 - r2 = 0
let
a = D^2
b = 2 * ((O - C) .D)
c = (O - C)^2 - r2
(eq3) is equivalent to a.t^2 + b.t + c = 0
=> Quadratic equation, 2 solutions
let d = b^2 - 4.a.c
solutions are
t1 = (- b - sqrt(d)) / 2.a
t2 = (- b + sqrt(d)) / 2.a
replace t in (eq0) by t1 and t2, and you get your points of intersections.
there are no intersection if d < 0, and only one if d = 0 (t1=t2=-b/2a)
that works both in 2D and 3D by the way.
Everything is better with Metal.
Endemoniada: You posted about a ray-circle intersection, but the post seems to have been deleted while I was answering it... I''d rather not let the answer to to waste, so I''ll post it here. Sorry if this is objectionable.
Things architects use: A compass? Bottom of a cup?
If your incoming rays are always perfectly horizontal? If so, you could just use the height h, of the ray, above the line parallel to the ray that passes through the centre of the circle (or the whole circle of which your arc would be a part). To rephrase: draw a radius from the centre of the circle to the point on the arc where the ray meets the arc. Draw a line perpendicular to the ray down to another line that is parallel to the ray that also passes through the centre of the circle. The length of that line is h.
Knowing h, which you should if you know what the ray is and where your circle is, and knowing the circle''s radius r, you can find the point where the circle and ray meet using trigonometry. The radius, perpendicular line (of length h), and line parallel to the ray form a right triangle. Thus:
h = r*sin(theta)
where theta is the angle between the parallel line and the radius to the intersection point.
since you know r and h, you can find theta = arcsin(h/r)
Knowhing theta and r you can then find the horizontal distance x from the centre of the circle to the point at which the ray meets the circle using
x = r*cos(theta)
The distances (x, h) tell you the point, relative to the centre of the circle where the ray meets the arc.
I''d draw a picture, but as you can see from your own attempts, it probly wouldn''t work.
If your rays aren''t always horizontal, things are a bit more complicated...
quote:
Original post by Endemoniada
Hi guys,
Well, after the last three hours using graph paper and one of those things the architects use to trace circles with I finally figured out what I need to do.
I need to see if a ray intersects an arc and if so where. The arc is a perfect quarter-circle and the rays come in from the outside, opposite to the rays emanating from the center of the circle.
Kinda like this (the \\\ lines are the curve):
___
\
\ <--------
\
|
|
Is there a formula for that ? I really hope so because it will solve almost all my problems.
Thanks.
Things architects use: A compass? Bottom of a cup?
If your incoming rays are always perfectly horizontal? If so, you could just use the height h, of the ray, above the line parallel to the ray that passes through the centre of the circle (or the whole circle of which your arc would be a part). To rephrase: draw a radius from the centre of the circle to the point on the arc where the ray meets the arc. Draw a line perpendicular to the ray down to another line that is parallel to the ray that also passes through the centre of the circle. The length of that line is h.
Knowing h, which you should if you know what the ray is and where your circle is, and knowing the circle''s radius r, you can find the point where the circle and ray meet using trigonometry. The radius, perpendicular line (of length h), and line parallel to the ray form a right triangle. Thus:
h = r*sin(theta)
where theta is the angle between the parallel line and the radius to the intersection point.
since you know r and h, you can find theta = arcsin(h/r)
Knowhing theta and r you can then find the horizontal distance x from the centre of the circle to the point at which the ray meets the circle using
x = r*cos(theta)
The distances (x, h) tell you the point, relative to the centre of the circle where the ray meets the arc.
I''d draw a picture, but as you can see from your own attempts, it probly wouldn''t work.
If your rays aren''t always horizontal, things are a bit more complicated...
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement