kill(all)$

maxima : intro to residue curve ( = simple batch process),version 1.0b,part 3
peter.vlasschaert@gmail.com,16/09/2020.

see  website
maxima : intro to residue curve ( = simple batch process),version 1.0,part 1,2

load packages,option
=================

load(lrats)$ ratprint:false$

Equilateral triangle
==============
ref :https://en.wikipedia.org/wiki/Equilateral_triangle

Equilateral triangle

coordinates
=========

p1: B=[0,0];

p1a: C=[1,0];  /* 10 => 1 = length : side*/

distance : |AB| = |BC| =|CA| = 1, fig every : divide by 10

How to find Height : AD   ( y ,value), x = value = 1/2
========================================
trignometry : 'right triangle BDA, γ/2'
( Maxima : radians : α,β,γ = π/3 = ' 60°')

p2a:BD = .5;
p2b:γ=(π/3);

p3:tan(γ/2) = BD/AD;
p3a:solve(p3,AD)[1];
p3b:lratsubst([p2a,p2b],p3a);

computation : ref base :γ/2 angle.

p2c:A=[1/2,AD];

p2c1:lratsubst([p3b],p2c);

find x,y: value  A,B,C
----------------------------

p4a:xA = lratsubst([p2c1],rhs(p2c1)[1]);
p4a1:yA = lratsubst([p2c1],rhs(p2c1)[2]);
p4b:xB = lratsubst([p1],rhs(p1)[1]);
p4b1:yB = lratsubst([p1],rhs(p1)[2]);
p4c:xC = lratsubst([p1a],rhs(p1a)[1]);
p4c1:yC = lratsubst([p1a],rhs(p1a)[2]);

Barycentric coordinates  (a,b,c,....) → (x,yz,.......)
========================================
2D:triangle    : (x,y)   → (a*(A) +b*(B)+c*(C))/(a+b+c)                   (1)
3D:tetraeder : (x,y,z) → (a*(A) +b*(B)+c*(C)+d*(D))/(a+b+c+d)   (2)

example  :triangle :  fig1
===================

 (a,b,c) → (x_t,y_t)
--------------------------

p5:[p4a,p4a1,p4b,p4b1,p4c,p4c1]$

p5c:a+b+c;

p5c1:listofvars(p5c);

p5a:x_t=(a*xA+b*xB+c*xC)/p5c; 
p5aa:lratsubst(p5,p5a);      /* x values :example */
p5b:y_t=(a*yA+b*yB+c*yC)/p5c;
p5bb:lratsubst(p5,p5b);      /* y values :example */
p5cc:p5c = 1;                /* are fixed value = k, constraint */

 (x_t,y_t) → (a,b,c)
-------------------------------

p5d:[p5aa,p5bb,p5cc];

use : constraint p5d into ( x_t,y_t)

p5d1:lratsubst([p5d[3]],p5d);

p5d2:makelist(p5d1[i],i,1,2);

p5da:flatten(solve(p5d,p5c1));

check :p5da , coordinates point A , a=1,b=0,c=0
======================================
example : xA=1/2,yA=sqrt(3)/2,use : p5da

p6:[x_t=1/2,y_t=sqrt(3)/2];
p6a:lratsubst(p6,p5da);

rem : a=1 ( A = 100% ,side BC : A = 0 %),chemical composition,see figure 1,above
=> see :check 'below',(r1 & r2)

analog : b=1(B = 100%,side AC: B = 0 %),chemical composition,see figure 1,above
analog : c=1(C = 100%,side AB: C = 0 %),chemical composition,see figure 1,above
---------------------------------------------------------------------------------------------------------------------
excercise: to show  that

Equilateral triangle (x_t,y_t) → right triangle ( used :chemical engineering)
========================================================

general transformation : Affine transformation.
---------------------------------------------------------------

ref 1:https://en.wikipedia.org/wiki/Affine_transformation
ref 2:Geometry ( second edition),the open university, Cambridge.

;

a)  matrix : representation
------------------------------------

MA: matrix(
 [Ax,Bx,Cx], 
 [Ay,By,Cy], 
 [1,1,1]
);

MB: matrix(
 [A1x,B1x,C1x], 
 [A1y,B1y,C1y], 
 [1,1,1]
);

M:ratsimp(MB.invert(MA));

b) transformation  (x_f,y_f,1)' = M .(x_t,y_t,1)'
-------------------------------------------------------------
' = transpose ( row vector => column vector)

p7a:[x_t,y_t,1];
p7b:[x_f,y_f,1];

p8:p7b=M.p7a;   /* math => A*X_t = X_f , X = column vector*/

p8a:p7b[1]=(rhs(p8)[1])[1];
p8b:p7b[2]=(rhs(p8)[2])[1];

c) inverse transformation =  M^(-1)
===========================

q1:ratsimp(invert(M)); /* math =>  X_t = A^(-1)*X_f, X =column vector */

q1[1];
q1[2];
q1[3];

x_t = q1[1][1]*p7b[1]+q1[1][2]*p7b[2]+q1[1][3]*p7b[3];

y_t = sum(q1[2][i]*p7b[i],i,1,length(M));

-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

example : Equilateral triangle (A,B,C)
=============================

mp1:[Ax=1/2,Ay=sqrt(3)/2,Bx=0,By=0,Cx=1,Cy = 0];

right trangle :(A1,B1,C1)    
===================
angl(A1,C1) = π/2 = 90°

mp2:[A1x=0,A1y=1,B1x=0,B1y=0,C1x=1,C1y = 0];

combination : Eq & Right
===================

mp3:append(mp1,mp2);

mp4:[x_t = 1/2,y_t=sqrt(3)/2]; /*point A :Eq */

mp5:append(mp4,mp3);

calculation :use ,{p8a,p8b},check
---------------------------------------------

r1:lratsubst(mp5,p8a);   /*coordinates A1 ;Right*/
r2:lratsubst(mp5,p8b);

r3:[rhs(r1),rhs(r2)];

Why to do this : show your data from one ternary plot to other ternary plot

rem :transformation of any point Eq (=Triangle ) project on Right(=Triangle.).
rem : We can use principels for 3D conversion ,see :Barycentric coordinates,'above'