interpolation - Algorithm to iteratively discover points on an arc described by three points -
i writing graphics application needs calculate , display list of points along curve arc described 3 points.
lets have points (1,1), (2,4) , (5,2). need algorithm can give me values of y each x 1 5 fall on interpolated arc.
i'm sure simple task math whizes out there, me it's bit beyond mathematical payscale.
thanks in advance!
so problem how compute center c = (c1, c2)
, radius r
of circumference given 3 points p = (p1, p2)
, q = (q1, q2)
, s = (s1, s2).
the idea simple. consists in realizing that, definition, center has same distance 3 points p
, q
, s.
now, set of points equidistant p
and q
perpendicular segment pq
incident @ mid point (p+q)/2
. similarly, set of points equidistant q
, s
perpendicular qs
passing thru (q+s)/2.
so, center c
must intersection of these 2 lines.
let's compute parametric equations of these 2 straight lines.
for need 2 additional functions call dist(a,b)
computes distance between points a
, b
, perp(a,b)
normalizes vector b-a
dividing length (or norm) , answers perpendicular vector normalized vector (keep in mind perpendicular (a,b)
(-b,a)
because inner product 0
)
dist((a1,a2),(b1,b2)) return sqrt(square(b1-a1) + square(b2-a2)) perp((a1,a2),(b1,b2)) dist := dist((a1,a2),(b1,b2)). := (b1-a1)/dist. b := (b2-a2)/dist. return (-b,a).
we can write parametric expressions of our 2 lines
(p+q)/2 + perp(p,q)*t (q+s)/2 + perp(q,s)*u
note both parameters different, hence introduction of 2 variables t
, u
.
equating these parametric expressions:
(p+q)/2 + perp(p,q)*t = (q+s)/2 + perp(q,s)*u
which consists of 2 linear equations, 1 each coordinate, , 2 unknowns t
, u
(see below). solution of 2x2 system gives values of parameters t
, u
injected parametric expressions give center c
of circumference.
once c
known, radius r
can calculated r := dist(p,c).
linear equations
(p+q)/2 + perp(p,q)*t = (q+s)/2 + perp(q,s)*u
first linear equation (coordinate x)
(p1+q1)/2 + (p2-q2)/dist(p,q)*t = (q1+s1)/2 + (q2-s2)/dist(q,s)*u
second linear equation (coordinate y)
(p2+q2)/2 + (q1-p1)/dist(p,q)*t = (q2+s2)/2 + (s1-q1)/dist(q,s)*u
linear system (2x2)
(p2-q2)/dist(p,q)*t + (s2-q2)/dist(q,s)*u = (s1-p1)/2 (q1-p1)/dist(p,q)*t + (q1-s1)/dist(q,s)*u = (s2-p2)/2
Comments
Post a Comment