Commit 88567a35 authored by Benoit Barbot's avatar Benoit Barbot
Browse files

fix bezier

parent 1e8f667a
......@@ -263,8 +263,8 @@ module Circle =
if dx >= 0.0 then
let t1 = ((sqrt dx) -. xB) /. (2.0 *. xA)
and t2 = (-.(sqrt dx) -. xB) /. (2.0 *. xA) in
let y1 = yA *. t1 *.t1 +. yB *. t1 +. yC
and y2 = yA *. t2 *.t2 +. yB *. t2 +. yC in
let y1 = yA*.t1*.t1 +. yB*.t1 +. yC
and y2 = yA*.t2*.t2 +. yB*.t2 +. yC in
let eps t x = t>=0.0 && t<=1.0 && abs_float x <= 1.5 *. thick in
eps t1 y1 || eps t2 y2
else false
......@@ -291,29 +291,31 @@ module Circle =
and p1 = tos control1
and p2 = tos control2
and p3 = tos epos in
let xA,yA = p3 -.. (mult 3.0 p2) +.. (mult 3.0 p1) -.. p0
and xB,yB = (mult 3.0 p2) -.. (mult 6.0 p1) +.. (mult 3.0 p0)
and xC,yC = (mult 3.0 p1) -.. (mult 3.0 p0)
and xD,yD = p0 -.. mouse_pos in
(*let dx = 18.0*.xA*.xB*.xC*.xD -. 4.0*.xB*.xB*.xB*.xD +. xB*.xB*.xC*.xC
-. 4.0*.xA*.xC*.xC*.xC -. 27.0*.xA*.xA*.xD*.xD in*)
let p = (3.0*.xA*.xC -. xB*.xB) /. (3.0 *. xA *.xA)
and q = (2.0*.xB*.xB*.xB -. 9.0*.xA*.xB*.xC +. 27.0*.xA*.xA*.xD)
/. (27.0 *.xA*.xA*.xA) in
if p <= 0.0 then
let sqp = sqrt (-.p/.3.0) in
let tk k = 2.0 *. sqp *.
cos ((1.0 /.3.0)*.(acos ( 3.0*.q /. (2.0 *.p*.sqp))) -. 2.0*.pi*.k/.3.0)
in
let xdiv,ydiv = p3 -.. (mult 3.0 p2) +.. (mult 3.0 p1) -.. p0 in
if xdiv=0.0 then (print_endline "not cubic"; false)
else
let xa,ya = vect_div ((mult 3.0 p2) -.. (mult 6.0 p1) +.. (mult 3.0 p0)) (xdiv,1.0)
and xb,yb = vect_div ((mult 3.0 p1) -.. (mult 3.0 p0)) (xdiv,1.0)
and xc,yc = vect_div (p0 -.. mouse_pos ) (xdiv,1.0) in
let qQ = (xa*.xa -. 3.0*.xb)/.9.0
and rR = (2.0*.xa*.xa*.xa -. 9.0*.xa*.xb +. 27.0*.xc)/. 54.0 in
let delta = qQ*.qQ*.qQ -. rR*.rR in
let eps t =
let y = ydiv*.t*.t*.t +. ya*.t*.t +. yb*.t +. yc in
t>=0.0 && t<=1.0 && abs_float y <= 1.5 *. thick in
if delta >=0.0 then
let theta = acos (rR /. (sqrt (qQ*.qQ*.qQ))) in
let tk k = -.xa/.3.0 -. 2.0*.(sqrt qQ)*.(cos (theta/.3.0 +. 2.0*.pi*.k/.3.0)) in
let t0 = tk 0.0
and t1 = tk 1.0
and t2 = tk 2.0 in
let y0 = yA*.t0*.t0*.t0 +. yB*.t0*.t0 +. yC*.t0 +. yD
and y1 = yA*.t1*.t1*.t1 +. yB*.t1*.t1 +. yC*.t1 +. yD
and y2 = yA*.t2*.t2*.t2 +. yB*.t2*.t2 +. yC*.t2 +. yD in
let eps t x = t>=0.0 && t<=1.0 && abs_float x <= 1.5 *. thick in
eps t0 y0 || eps t1 y1 || eps t2 y2
else (print_endline "out"; false)
and t1 = tk (-.1.0)
and t2 = tk 1.0 in
eps t0 || eps t1 || eps t2
else
let sr = if rR<0.0 then -.1.0 else if rR=0.0 then 0.0 else 1.0 in
let aA = sr*.(sqrt ((abs_float rR)+.(sqrt (-.delta)))) in
let bB = if aA=0.0 then 0.0 else qQ/.aA in
let t = aA +. bB -. aA/.3.0 in
eps t
end
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment