Dev:Linking to Blines - Equations
WARNING: This text is under HEAVY development. Please be patient.
Contents
Main equations
- Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://api.formulasearchengine.com/v1/":): {\displaystyle (x_1,y_1), (x_2,y_2)} - vertices, defining bline segment
- Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://api.formulasearchengine.com/v1/":): {\displaystyle (x,y) } - current bline point
- Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://api.formulasearchengine.com/v1/":): {\displaystyle (x^{t2}_1,y^{t2}_1), (x^{t1}_2,y^{t1}_2)} - tangent points defining bline segment
- Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://api.formulasearchengine.com/v1/":): {\displaystyle (x^{t1},y^{t1}), (x^{t2},y^{t2})} - coordinates of yellow (t1) and red (t2) tangents (absolute)
- u - Amount of current segment, [0,1]
- Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://api.formulasearchengine.com/v1/":): {\displaystyle (x,y) = (1-u)^3 (x_1,y_1) + 3 u(1-u)^2 (x^{t2}_1,y^{t2}_1) + 3 u^2 (1-u) (x^{t1}_2,y^{t1}_2) + u^3 (x_2,y_2)} - bline point
Relative tangents
O'kay, I know, the Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://api.formulasearchengine.com/v1/":): {\displaystyle (x^{t1},y^{t1}), (x^{t2},y^{t2})} defining absolute position of tangents, but in synfig we have their coordinates relative to vertex. Moreover, coordinates of yellow tangent are inverted.
Let's say:
- Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://api.formulasearchengine.com/v1/":): {\displaystyle (\Delta x^{t1},\Delta y^{t1})} - relative coordinates of yellow tangent
- Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://api.formulasearchengine.com/v1/":): {\displaystyle (\Delta x^{t2},\Delta y^{t2})} - relative coordinates of red tangent
Then:
- Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://api.formulasearchengine.com/v1/":): {\displaystyle (x^{t1},y^{t1}) = (x,y) - (\Delta x^{t1},\Delta y^{t1})}
- Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://api.formulasearchengine.com/v1/":): {\displaystyle (x^{t2},y^{t2}) = (x,y) + (\Delta x^{t2},\Delta y^{t2})}
Make substitution:
- Bline point: Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://api.formulasearchengine.com/v1/":): {\displaystyle (x,y) = (1-(3u^2-2u^3)) (x_1,y_1) + 3u(1-u)^2 (\Delta x ^{t2}_1,\Delta y^{t2}_1) - 3u^2(1-u) (\Delta x^{t1}_2, \Delta y^{t1}_2) + (3u^2-2u^3) (x_2,y_2)}
Tangent coordinates
<dooglus> look at etl/_calculus.h <dooglus> class derivative<hermite<T> > <dooglus> T a = func[0], b = func[1], c = func[2], d = func[3]; <dooglus> typename hermite<T>::argument_type y(1-x); <dooglus> return ((b-a)*y*y + (c-b)*x*y*2 + (d-c)*x*x) * 3;
- Can't understand, why *3? --Zelgadis 05:31, 8 March 2008 (EST)
For x:
- Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://api.formulasearchengine.com/v1/":): {\displaystyle \Delta x^{t1} = \Delta x^{t2} = (1-u)^2 \Delta x^{t2}_1 + 2u(1-u) ((x_2 + \Delta x^{t1}_2) - (x_1 + \Delta x^{t2}_1)) + u^2 \Delta x^{t1}_2 = } Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://api.formulasearchengine.com/v1/":): {\displaystyle = -2u(1-u)x_1 + (1-u^2)\Delta x^{t2}_1 + u(2-u)\Delta x^{t1}_2 + u(1-u)x_2}
Zelgadis, you wrong!
O'kay I understand what equations above could be wrong. But no one will argue what equations for bline point and tangents generally have form:
- Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://api.formulasearchengine.com/v1/":): {\displaystyle (x,y) = c_1(u) (x_1,y_1) + c_2(u) (x^{t2}_1,y^{t2}_1) + c_3(u) (x^{t1}_2,y^{t1}_2) + c_4(u) (x_2,y_2)}
- Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://api.formulasearchengine.com/v1/":): {\displaystyle \Delta x^{t1} = \Delta x^{t2} = c_5(u) (x_1,y_1) + c_6(u) (\Delta x^{t2}_1, \Delta y^{t2}_1) + c_7 (\Delta x^{t1}_2, \Delta y^{t1}_2) + c_8(u) (x_2,y_2)}
where Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://api.formulasearchengine.com/v1/":): {\displaystyle c_i(u)} - some function from 'u' argument
So I will use this notation further.
General model
The problem: see Linking_to_Blines#Creating_loops
So we need to determine position of vertex engaged in loop if she attachet ot some position of other bline.
- NOTICE: We need such recalculation only for cases when in loop included only 1 segment from each bline. Like this:
- We don't need to do recalculation for cases like those:
So, we have N blines (N bline segments) engaged in a loop. Let'
To determine the x coordinate of vertex what finalizes the loop we need to solve matrix equation having form
Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://api.formulasearchengine.com/v1/":): {\displaystyle (A - B)*\alpha = \beta}
- NOTE: Solution formulas for y coordinate will be the same.
- Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://api.formulasearchengine.com/v1/":): {\displaystyle A, B} - matrices 4N x 4N
- Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://api.formulasearchengine.com/v1/":): {\displaystyle \alpha, \beta} - 4N column vectors
- Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://api.formulasearchengine.com/v1/":): {\displaystyle \alpha} - is unknown quantity
Each line in matrix or column vector corresponding to particular vertex or it's tangent.
After solving system we will find column vector Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://api.formulasearchengine.com/v1/":): {\displaystyle \alpha} which have form: Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://api.formulasearchengine.com/v1/":): {\displaystyle (x^{[1]}_1,x^{[1]}_{t1},x^{[1]}_{t2},x^{[1]}_2, x^{[2]}_1,x^{[2]}_{t1},x^{[2]}_{t2},x^{[2]}_2, ... ,x^{[N]}_1,x^{[N]}_{t1},x^{[N]}_{t2},x^{[N]}_2)} where Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://api.formulasearchengine.com/v1/":): {\displaystyle x^{[i]}_j} - point j of bline [i] and Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://api.formulasearchengine.com/v1/":): {\displaystyle x^{[i]}_tj} tangent of point j of bline i.
So:
- the first line of each matrix or column vector corresponding to first vertex of first bline,
- second line - to tangent of first vertex of first bline,
- third line - to tangent of second vertex of first bline,
- fourth - second vertex of first bline,
- fifth - first vertex of second bline,
- ...and so on...
- NOTE: Talking about bline we are talking about single (!) segment of bline which engaged in loop. That's why I not specify which tangent (yellow or red) we using - it's always tangent for current segment.
Column vector Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://api.formulasearchengine.com/v1/":): {\displaystyle \beta} have following structure. If position of vertex/tangent corresponding to vector element is "static" (i.e. it's not linked any other bline segment of the loop) then vector element is Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://api.formulasearchengine.com/v1/":): {\displaystyle \beta_i} where Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://api.formulasearchengine.com/v1/":): {\displaystyle \beta_i} is current x coordinate of this vector/tangent. If vertex/tangent is not "static" then corresponding vector element is zero.
- NOTE: When we calling vertex position "static" it's not means what vertex not linked to anything. The vertex could be linked to bline and still considered as "static" if that bline is not engaged into loop what we processing.
B matrix is zero-filled 4Nx4N matrix which we modifying in folowing way (rows and columns in matrix are numbered from 1):
- if first vertex of bline [i] is linked to bline [j] then element at ( (i-1)*4+1 , (j-1)*4+1 ) = 1
- if tangent of first vertex of bline [i] is linked to bline [j] then element at ( (i-1)*4+2 , (j-1)*4+2 ) = 1
- if tangent of second vertex of bline [i] is linked to bline [j] then element at ( (i-1)*4+3 , (j-1)*4+3 ) = 1
- if second vertex of bline [i] is linked to bline [j] then element at ( (i-1)*4+4 , (j-1)*4+4 ) = 1
A matrix is modified E matrix. Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://api.formulasearchengine.com/v1/":): {\displaystyle E = \begin{pmatrix} 1 & 0 & 0& ... & 0 \\ 0 & 1 & 0& ... & 0 \\ 0 & 0 & 1 & ... & 0 \\...&...&...&...&... \\ 0 & 0 & 0& ... & 1 \\ \end{pmatrix}}
It is modified in such way:
- if first vertex of bline [i] is linked to bline [j] then elements in line (j-1)*4+1 at positions (j-1)*4+1, (j-1)*4+2, (j-1)*4+3, (j-1)*4+4 are replaced with Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://api.formulasearchengine.com/v1/":): {\displaystyle c^{[j]}_1(u_i), c^{[j]}_2(u_i), c^{[j]}_3(u_i), c^{[j]}_4(u_i)}
Examples
Ok, I sure you guys are wondering how is this work. (I personally wondering IF this works or not :D). Let's view some examples.
One spline
Case 1: Bline A. A2 linked to A with tangent.
For x coordinates we have following system of equations:
- Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://api.formulasearchengine.com/v1/":): {\displaystyle x_{A1} = c_1}
- Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://api.formulasearchengine.com/v1/":): {\displaystyle x^{t2}_{A1} = c_2}
- Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://api.formulasearchengine.com/v1/":): {\displaystyle \Delta x^{t1}_{A2} = -2u(1-u)x_{A1} + (1-u^2)\Delta x^{t2}_{A1} + u(2-u)\Delta x^{t1}_{A2} + u(1-u)x_{A2}}
- Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://api.formulasearchengine.com/v1/":): {\displaystyle x_{A2} = (1-(3u^2-2u^3)) x_{A1} + 3u(1-u)^2 \Delta x ^{t2}_{A1} - 3u^2(1-u) \Delta x^{t1}_{A2} + (3u^2-2u^3) x_{A2}}
Transform:
- Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://api.formulasearchengine.com/v1/":): {\displaystyle x_{A1} = c_1}
- Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://api.formulasearchengine.com/v1/":): {\displaystyle x^{t2}_{A1} = c_2 }
- Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://api.formulasearchengine.com/v1/":): {\displaystyle -2u(1-u)x_{A1} + (1-u^2)\Delta x^{t2}_{A1} + (u(2-u)-1)\Delta x^{t1}_{A2} + u(1-u)x_{A2} = 0}
- Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://api.formulasearchengine.com/v1/":): {\displaystyle (1-(3u^2-2u^3)) x_{A1} + 3u(1-u)^2 \Delta x ^{t2}_{A1} - 3u^2(1-u) \Delta x^{t1}_{A2} + (3u^2-2u^3-1) x_{A2} = 0}
So, we must solve the 4x4 matrix equation: Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://api.formulasearchengine.com/v1/":): {\displaystyle ( \begin{pmatrix} 1 & 0 & 0 & 0 \\ 0 & 1 & 0 &0 \\ (-2u(1-u) & (1-u^2) & u(2-u) & u(1-u) \\ (1-(3u^2-2u^3)) & 3u(1-u)^2 & -3u^2(1-u) & (3u^2-2u^3) \end{pmatrix} -\begin{pmatrix} 0&0&0&0 \\ 0&0&0&0\\ 0&0&1&0 \\ 0&0&0&1\end{pmatrix}) \cdot \begin{pmatrix} x_{A1} \\ x^{t2}_{A1} \\ x^{t1}_{A2} \\ x_{A2} \end{pmatrix} = \begin{pmatrix} c_1 \\ c_2 \\ 0 \\ 0 \end{pmatrix}}
dooglus, can you check how this formula works in code? Something like:
- Create bline with 2 points - A1,A2
- Select point A2, right click on bline -> "Link to bline"
- Place (not link!) at the position calculated by this formula. If we'll have A2 on bline after that then it's ok for now, if not - something wrong.
I know we need a general formula but if this won't work then I definitely not right.
Case 2: Bline A. A2 linked to A without tangent.
The 4th line just replaced with:
- Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://api.formulasearchengine.com/v1/":): {\displaystyle \Delta x^{t1}_{A2} = c_3}
Two splines
If we got circular reference with two blines, then we must solve equation with matrix 8x8.
Conclusion
Maybe formulas are not correct, but I think you've got the idea: For N Bline segments in loop we have 4N equations. If vertex is linked then we got appropriate equation, depending on what is linked. If vertex is not linked - just assigning constants.