_TITLE "Checking TempodiBasic formula for Coplanar Points" ' 2020-06-23 ref: https://www.qb64.org/forum/index.php?topic=2745.0
_DELAY .25 'allow time to load before moving
'given 3d tri
'(1,1,0)
'(1,0,1)
'(0,1,1)
DIM SHARED tri
(2) AS xyz
' This turns out to be Equilateral triangle from my experiments of getting 3D angles tri(0).x = 1: tri(0).y = 1: tri(0).z = 0
tri(1).x = 1: tri(1).y = 0: tri(1).z = 1
tri(2).x = 0: tri(2).y = 1: tri(2).z = 1
'given test cases 6 points in 3d tri or not? 2 are made up the remaider are in which is which?
'(.66,.66,.66)
'(.46,.66,.86)
'(.83,.89,.26)
'(.55,.55,.55)
'(.75,.79,.46)
'(.79,.89,.66)
test(0).x = .66: test(0).y = .66: test(0).z = .66 'on/in
test(1).x = .46: test(1).y = .66: test(1).z = .86
test(2).x = .83: test(2).y = .89: test(2).z = .26
test(3).x = 100: test(3).y = -100: test(3).z = 100 '
test(4).x = .75: test(4).y = .79: test(4).z = .46
test(5).x = 0: test(5).y = 0: test(5).z = 0 '
Initialize
FOR i
= 0 TO 5 'test points to Stx triangle, we know 4 are inside of triangle so MUST also be Coplanar P(4).x = test(i).x: P(4).y = test(i).y: P(4).z = test(i).z
TF = IsInner
PRINT "For test point"; i;
" IsInner test returned"; TF
PRINT "Number 3 and 5 should not be true" dist3D
= SQR((p1.x
- p2.x
) ^ 2 + (p1.y
- p2.y
) ^ 2 + (p1.z
- p2.z
) ^ 2)
' using STx known triangle and test points already tested
P(i).x = tri(i - 1).x
P(i).y = tri(i - 1).y
P(i).z = tri(i - 1).z
PRINT P
(i
).x
, P
(i
).y
, P
(i
).z
' it calculates centroid
P(5).x = (P(1).x + P(2).x + P(3).x) / 3
P(5).y = (P(1).y + P(2).y + P(3).y) / 3
P(5).z = (P(1).z + P(2).z + P(3).z) / 3
PRINT P
(5).x
, P
(5).y
, P
(5).z
'it calculates midpoints DEF
P(6).x = (P(1).x + P(2).x) / 2
P(6).y = (P(1).y + P(2).y) / 2
P(6).z = (P(1).z + P(2).z) / 2
PRINT P
(6).x
, P
(6).y
, P
(6).z
P(7).x = (P(3).x + P(2).x) / 2
P(7).y = (P(3).y + P(2).y) / 2
P(7).z = (P(3).z + P(2).z) / 2
PRINT P
(7).x
, P
(7).y
, P
(7).z
P(8).x = (P(1).x + P(3).x) / 2
P(8).y = (P(1).y + P(3).y) / 2
P(8).z = (P(1).z + P(3).z) / 2
PRINT P
(8).x
, P
(8).y
, P
(8).z
'PA+PB+PC <= 2*(PD+PE+PF)+3*PG
DIM PA
, PB
, PC
, PD
, PE
, PF
, PG
PA = dist3D(P(4), P(1)): PB = dist3D(P(4), P(2)): PC = dist3D(P(4), P(3))
PD = dist3D(P(4), P(6)): PE = dist3D(P(4), P(7)): PF = dist3D(P(4), P(8))
PG = dist3D(P(4), P(5))
IF PA
+ PB
+ PC
<= 2 * (PD
+ PE
+ PF
) + 3 * PG
THEN IsInner
= -1 PRINT PA
+ PB
+ PC
, 2 * (PD
+ PE
+ PF
) + 3 * PG
'IF (Distance(P(4), P(1)) + Distance(P(4), P(2)) + Distance(P(4), P(3))) <= 3 * Distance(P(4), P(5)) + 2 * (Distance(P(4), P(6)) + Distance(P(4), P(7)) + Distance(P(4), P(8))) THEN IsInner = True ELSE IsInner = False
' debug output
'PRINT (Distance(P(4), P(1)) + Distance(P(4), P(2)) + Distance(P(4), P(3))) <= 3 * Distance(P(4), P(5)) + 2 * (Distance(P(4), P(6)) + Distance(P(4), P(7)) + Distance(P(4), P(8))); " ";
'PRINT (Distance(P(4), P(1)) + Distance(P(4), P(2)) + Distance(P(4), P(3))), 3 * Distance(P(4), P(5)) + 2 * (Distance(P(4), P(6)) + Distance(P(4), P(7)) + Distance(P(4), P(8)))