Difference between revisions of "Dev:Linking to Blines - Equations"

From Synfig Studio :: Documentation
Jump to: navigation, search
m (Relative tangent coordinates)
(rewrite)
Line 1: Line 1:
 
== Main equations ==
 
== Main equations ==
  
* <math>(x_1,y_1), (x_2,y_2)</math> - points of bline vertex
+
* <math>(x_1,y_1), (x_2,y_2)</math> - vertices, defining bline segment
* <math>(x^t_1,y^t_1), (x^t_2,y^t_2)</math> - tangent points
+
* <math>(x,y) </math> - current bline point
* <math> (x,y) </math> - current bline point
+
* <math>(x^{t2}_1,y^{t2}_1), (x^{t1}_2,y^{t1}_2)</math> - tangent points defining bline segment
* <math>(x^t_L,y^t_L), (x^t_N,y^t_N)</math> - tangents of current  point
+
* <math>(x^{t1},y^{t1}), (x^{t2},y^{t2})</math> - coordinates of yellow (t1) and red (t2) tangents (absolute)
 
* u - Amount of current segment, [0,1]
 
* u - Amount of current segment, [0,1]
  
* <math>(x,y) = (1-u)^3 (x_1,y_1) + 3 u(1-u)^2  (x^t_1,y^t_1) + 3 u^2 (1-u)  (x^t_2,y^t_2) + u^3 (x_2,y_2)</math> - bline point
+
* <math>(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)</math> - bline point
* <math>(x^t_L,y^t_L) = (1-u)^2 (x_1,y_1) + 2u(1-u)(x^t_1,y^t_1) + u^2(x^t_2,y^t_2)</math> - yellow tangent of bline point
+
* <math>(x^{t1},y^{t1}) = (1-u)^2 (x_1,y_1) + 2u(1-u)(x^{t2}_1,y^{t2}_1) + u^2(x^{t1}_2,y^{t1}_2)</math> - coordinates of yellow tangent for current bline point
* <math>(x^t_N,y^t_N) = (1-u)^2 (x^t_1,y^t_1) + 2u(1-u)(x^t_2,y^t_2) + u^2(x_2,y_2)</math> - red tangent of bline point
+
* <math>(x^{t2},y^{t2}) = (1-u)^2 (x^{t2}_1,y^{t2}_1) + 2u(1-u)(x^{t1}_2,y^{t1}_2) + u^2(x_2,y_2)</math> - red tangent of bline point
  
== How I found tangents formula ==
+
=== How I found tangents formula ===
  
A,B,C,D defining spline segment. A,D - verticles, B,C - tangents.
+
A,B,C,D defining spline segment. A,D - vertices, B,C - tangents:
 +
 
 +
<math>A = (x_1,y_1); B=(x^{t2}_1,y^{t2}_1); C=(x^{t1}_2,y^{t1}_2);  D = (x_2,y_2)</math>
  
 
* put a point on each line, some percentage of the way along each
 
* put a point on each line, some percentage of the way along each
** M on (A,B): <math>(x_1,y_1)(1-u) + (x^t_1,y^t_1)u</math>
+
** M on (A,B): <math>(x_1,y_1)(1-u) + (x^{t2}_1,y^{t2}_1)u</math>
** N on (B,C): <math>(x^t_1,y^t_1)(1-u) + (x^t_2,y^t_2)u</math>
+
** N on (B,C): <math>(x^{t2}_1,y^{t2}_1)(1-u) + (x^{t1}_2,y^{t1}_2)u</math>
** K on (C,D): <math>(x^t_2,y^t_2)(1-u) + (x^2,y^2)u</math>
+
** K on (C,D): <math>(x^{t1}_2,y^{t1}_2)(1-u) + (x^2,y^2)u</math>
 
* then draw new lines from the point on A-B to the point on B-C, and from the point on B-C to the point on C-D; and put new points on those 2, the same percentage of the way along each
 
* then draw new lines from the point on A-B to the point on B-C, and from the point on B-C to the point on C-D; and put new points on those 2, the same percentage of the way along each
** T1 on (M,N): <math>M(1-u) + N u = ((x_1,y_1)(1-u) + (x^t_1,y^t_1)u)(1-u) + ((x^t_1,y^t_1)(1-u) + (x^t_2,y^t_2)u)u</math>
+
** T1 on (M,N): <math>M(1-u) + N u = ((x_1,y_1)(1-u) + (x^{t2}_1,y^{t2}_1)u)(1-u) + ((x^{t2}_1,y^{t2}_1)(1-u) + (x^t_2,y^t_2)u)u = </math><math> =(1-u)^2 (x_1,y_1) + 2u(1-u)(x^{t2}_1,y^{t2}_1) + u^2(x^{t1}_2,y^{t1}_2)</math>
** T2 on (N,K): <math>N(1-u) + K u = ((x^t_1,y^t_1)(1-u) + (x^t_2,y^t_2)u)(1-u) + ((x^t_2,y^t_2)(1-u) + (x^2,y^2)u) u</math>
+
** T2 on (N,K): <math>N(1-u) + K u = ((x^{t2}_1,y^{t2}_1)(1-u) + (x^{t1}_2,y^{t1}_2)u)(1-u) + ((x^{t1}_2,y^{t1}_2)(1-u) + (x^2,y^2)u) u = </math><math> = (1-u)^2 (x^{t2}_1,y^{t2}_1) + 2u(1-u)(x^{t1}_2,y^{t1}_2) + u^2(x_2,y_2)</math>
* then:
+
** T1 on (M,N): <math>(x^t_L,y^t_L) = (1-u)^2 (x_1,y_1) + 2u(1-u)(x^t_1,y^t_1) + u^2(x^t_2,y^t_2)</math> - yellow tangent of bline point
+
** T2 on (N,K): <math>(x^t_N,y^t_N) = (1-u)^2 (x^t_1,y^t_1) + 2u(1-u)(x^t_2,y^t_2) + u^2(x_2,y_2)</math> - red tangent of bline point
+
  
== Relative tangent coordinates ==
+
==== Relative tangent coordinates ====
  
O'kay, I know, the <math>(x^t_L,y^t_L), (x^t_N,y^t_N)</math> defining absolute position of tangents, but we want their coordinates relative to vertex. Moreover, coordinates of yellow tangent are inverted.
+
O'kay, I know, the <math>(x^{t1},y^{t1}), (x^{t2},y^{t2})</math> 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:
 
Let's say:
* <math>(\Delta x^L_t,\Delta y^L_t)</math> - relative coordinates of yellow tangent
+
* <math>(\Delta x^{t1},\Delta y^{t1})</math> - relative coordinates of yellow tangent
* <math>(\Delta x^N_t,\Delta y^N_t)</math> - relative coordinates of red tangent
+
* <math>(\Delta x^{t2},\Delta y^{t2})</math> - relative coordinates of red tangent
  
 
Then:
 
Then:
  
*<math>(x^t_L,y^t_L) = (x,y) - (\Delta x^L_t,\Delta y^L_t)</math>
+
*<math>(x^{t1},y^{t1}) = (x,y) - (\Delta x^{t1},\Delta y^{t1})</math>
*<math>(x^t_N,y^t_N) = (x,y) + (\Delta x^L_t,\Delta y^L_t)</math>
+
*<math>(x^{t2},y^{t2}) = (x,y) + (\Delta x^{t2},\Delta y^{t2})</math>
 +
 
 +
Make substitution:
 +
 
 +
...
  
 
== One spline ==
 
== One spline ==

Revision as of 11:00, 8 March 2008

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
  • 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}) = (1-u)^2 (x_1,y_1) + 2u(1-u)(x^{t2}_1,y^{t2}_1) + u^2(x^{t1}_2,y^{t1}_2)} - coordinates of yellow tangent for 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},y^{t2}) = (1-u)^2 (x^{t2}_1,y^{t2}_1) + 2u(1-u)(x^{t1}_2,y^{t1}_2) + u^2(x_2,y_2)} - red tangent of bline point

How I found tangents formula

A,B,C,D defining spline segment. A,D - vertices, B,C - tangents:

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 = (x_1,y_1); B=(x^{t2}_1,y^{t2}_1); C=(x^{t1}_2,y^{t1}_2); D = (x_2,y_2)}

  • put a point on each line, some percentage of the way along each
    • M on (A,B): 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)(1-u) + (x^{t2}_1,y^{t2}_1)u}
    • N on (B,C): 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)(1-u) + (x^{t1}_2,y^{t1}_2)u}
    • K on (C,D): 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}_2,y^{t1}_2)(1-u) + (x^2,y^2)u}
  • then draw new lines from the point on A-B to the point on B-C, and from the point on B-C to the point on C-D; and put new points on those 2, the same percentage of the way along each
    • T1 on (M,N): 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 M(1-u) + N u = ((x_1,y_1)(1-u) + (x^{t2}_1,y^{t2}_1)u)(1-u) + ((x^{t2}_1,y^{t2}_1)(1-u) + (x^t_2,y^t_2)u)u = } 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-u)^2 (x_1,y_1) + 2u(1-u)(x^{t2}_1,y^{t2}_1) + u^2(x^{t1}_2,y^{t1}_2)}
    • T2 on (N,K): 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 N(1-u) + K u = ((x^{t2}_1,y^{t2}_1)(1-u) + (x^{t1}_2,y^{t1}_2)u)(1-u) + ((x^{t1}_2,y^{t1}_2)(1-u) + (x^2,y^2)u) u = } 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-u)^2 (x^{t2}_1,y^{t2}_1) + 2u(1-u)(x^{t1}_2,y^{t1}_2) + u^2(x_2,y_2)}

Relative tangent coordinates

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:

...

One spline

Case: Bline A. A2 linked to A (with tangent).

A2 with its tangent belongs to A, so:

  • 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-u)^3 x_{A1} + 3u(1-u)^2 x^t_{A1} + 3u^2(1-u) x^t_{A2} + u^3 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^t_{A2} = (1-u)^2 x_{A1} + 2u(1-u) x^t_{A1} + u^2 x^t_{A2}}

Let's find 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}} 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^t_{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} = \frac{(1-u)^3 x_{A1} + 3u(1-u)^2 x^t_{A1} + 3u^2(1-u) x^t_{A2} }{1 - u^3}}
  • 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^t_{A2} = \frac{(1-u)^2 x_{A1} + 2u(1-u) x^t_{A1}} {1- u^2 }}

For 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 y_{A2}} 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 y^t_{A2}} formulas are the analogical:

  • 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 y_{A2} = \frac{(1-u)^3 y_{A1} + 3u(1-u)^2 y^t_{A1} + 3u^2(1-u) y^t_{A2} }{1 - u^3}}
  • 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 y^t_{A2} = \frac{(1-u)^2 y_{A1} + 2u(1-u) y^t_{A1}} {1- u^2 }}


So if we look closely at the equations, we will see that all 4 points (2 tangents and 2 vertices) are placed on line defined by .

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.

Two splines

...