[Closed] arc between two points?
Gravey: Gosh, I miss the days of college maths… wait, maybe not all that much Anyway, the functions are just a few substitutions away. For a start, let’s say we switch the distance function for a lenght of vector.
fn circumcenter p1 p2 p3 =
(
local BC = length (p3 - p2)
local CA = length (p3 - p1)
local AB = length (p2 - p1)
local u = BC^2*(CA^2+AB^2-BC^2)
local v = CA^2*(AB^2+BC^2-CA^2)
local w = AB^2*(BC^2+CA^2-AB^2)
barycentricToWorld p1 p2 p3 u v w
)
This is just to make the transtion easier to follow, as we now use each of these vectors as a variable and the dot product of the vector with itself substitutes the squared distance (getting rid of squaring the square root):
fn circumcenter p1 p2 p3 =
(
local a = p3 - p2
local b = p3 - p1
local c = p2 - p1
local u = dot a a * (dot b b + dot c c - dot a a)
local v = dot b b * (dot c c + dot a a - dot b b)
local w = dot c c * (dot a a + dot b b - dot c c)
barycentricToWorld p1 p2 p3 u v w
)
Now, all the negative dot product terms can also be subsituted,
dot a a == dot (b - c) (b - c)
dot a a == dot b b - 2 * dot b c + dot c c
dot b b == dot (c - -a) (c - -a)
dot b b == dot c c - 2 * dot c -a + dot a a --> dot -a -a == dot a a
dot c c == dot (a - b) (a - b)
dot c c == dot a a - 2 * dot a b + dot b b
So the three terms are in the end:
dot a a * (dot b b + dot c c - dot b b + 2 * dot b c - dot c c)
--> 2 * dot a a * dot b c
dot b b * (dot c c + dot a a - dot c c + 2 * dot c -a - dot a a)
--> 2 * dot b b * dot c -a
dot c c * (dot a a + dot b b - dot a a + 2 * dot a b - dot b b)
--> 2 * dot c c * dot a b
No square root anymore, just basic multiplication and stuff – of course here it’s no big deal
what’s wrong with this one:
fn circumcenter p1 p2 p3 =
(
fn barycentricToWorld p1 p2 p3 u v w = (u*p1 + v*p2 + w*p3) / (u + v + w)
local a = p3 - p2
local b = p1 - p3
local c = p2 - p1
local u = (dot a a) * (dot c b)
local v = (dot b b) * (dot c a)
local w = (dot c c) * (dot b a)
barycentricToWorld p1 p2 p3 u v w
)
fastest, cleanest…
Nothing it’s just perfect. Anyway thanks Swordslayer for very informative math lesson.