Archivo:Cardinal Spline Example.png

Cardinal_Spline_Example.png(720 × 480 píxeles; tamaño de archivo: 7 kB; tipo MIME: image/png)

Descripción
English: This image is a graphical representation of a Cardinal Spline. It is drawn on a 720x480 canvas and the curve has 10 control points. The tension is set to 0.1.

The red squares represent the position of the control points, and the red line represents the path of the curve.

The image was created with the following w:perl script:

use strict;
use Image::Magick;
use Math::Matrix;
use Math::Gradient qw(gradient);

my $rate = 500;
my $tension = 0.1;
my(@coords) = (
 [ 23, 24], [123, 64], [167,200], [ 18,285], [293,467],
 [699,205], [487,181], [358,222], [262,130], [238, 24]
 );

my $image = Image::Magick->new; # Create new image
$image ->Set(size=>'720x480'); # Set size
$image ->ReadImage('xc:white'); # Make it all white
foreach my $ra_coord (@coords) # For every set of coords in the list
 {
 my($x,$y) = @{$ra_coord}[0,1]; # Get the x and y
 $image ->Draw (
 primitive => 'rectangle',
 points => (($x-3).','.($y-3).' '.($x+3).','.($y+3)),
 fill => 'red'
 ); # Draw a small rectangle at each coord
 }
while (scalar(@coords) >= 4) # While there are at least 4 entries in the list
 {
 for my $u (gradient(0,1,$rate)) # iterate from 0 to 1 in 500 steps
 {
 my($x,$y) = &EvaluateCardinal2D(\@coords, $tension, $u); # Hand paramaters to formula
 $image ->Set("pixel\[$x,$y\]"=>'red'); # Set that pixel red
 }
 shift(@coords); # Remove the first entry of the list
 }
$image ->Write("Cardinal_Spline_Example.png"); # Save image

sub EvaluateCardinal2D
 {
 my($ra_coords,$T,$u) = @_;
 my $s = (1-$T)/2;
 my $u_matrix = new Math::Matrix # 4 x 1
 ( # Matrix based off the point in the curve
 [($u ** 3), ($u ** 2), ($u), (1) ]
 );
 my $cardinal_matrix = new Math::Matrix # 4 x 4
 ( # Guts of the Cardinal Spline formula
 [(-1 * $s), (2 - $s), ($s - 2), ($s) ],
 [(2 * $s), ($s - 3), (3-(2 * $s)), (-1 * $s) ],
 [(-1 * $s), (0), ($s), (0) ],
 [(0), (1), (0), (0) ],
 );
 my $x_matrix = new Math::Matrix # 1 x 4
 ( # X coords for point:
 [${${$ra_coords}[0]}[0]], # 1
 [${${$ra_coords}[1]}[0]], # 2
 [${${$ra_coords}[2]}[0]], # 3
 [${${$ra_coords}[3]}[0]] # 4
 );
 my $y_matrix = new Math::Matrix # 1 x 4
 ( # Y coords for point:
 [${${$ra_coords}[0]}[1]], # 1
 [${${$ra_coords}[1]}[1]], # 2
 [${${$ra_coords}[2]}[1]], # 3
 [${${$ra_coords}[3]}[1]] # 4
 );
 my $xt = int ($u_matrix * $cardinal_matrix * $x_matrix); # Compute for X
 my $yt = int ($u_matrix * $cardinal_matrix * $y_matrix); # Compute for Y
 return($xt,$yt);
 }
 

The above source code is released under the same conditions as the image itself. (PD by owner)

Missing from file history: Berland cropped the image 2007-03-05.
Fecha 17 October 2006
Fuente Trabajo propio
Autor H (talk) (Uploads)

Resumen

This image is a graphical representation of a Cardinal Spline. It is drawn on a 720x480 canvas and the curve has 10 control points. The tension is set to 0.1.

The red squares represent the position of the control points, and the red line represents the path of the curve.

The image was created with the following w:perl script:

use strict;
use Image::Magick;
use Math::Matrix;
use Math::Gradient qw(gradient);

my $rate        = 500;
my $tension     = 0.1;
my(@coords)     = (
                   [ 23, 24],     [123, 64],     [167,200],     [ 18,285],     [293,467],
                   [699,205],     [487,181],     [358,222],     [262,130],     [238, 24]
                  );

my $image       = Image::Magick->new;           # Create new image
$image          ->Set(size=>'720x480');         # Set size
$image          ->ReadImage('xc:white');        # Make it all white
foreach my $ra_coord (@coords)                  # For every set of coords in the list
  {
  my($x,$y)     = @{$ra_coord}[0,1];            # Get the x and y
  $image        ->Draw  (
                         primitive      => 'rectangle',
                         points         => (($x-3).','.($y-3).' '.($x+3).','.($y+3)),
                         fill           => 'red'
                        );                      # Draw a small rectangle at each coord
  }
while (scalar(@coords) >= 4)                    # While there are at least 4 entries in the list
  {
  for my $u (gradient(0,1,$rate))               # iterate from 0 to 1 in 500 steps
    {
    my($x,$y)   = &EvaluateCardinal2D(\@coords, $tension, $u);      # Hand paramaters to formula
    $image      ->Set("pixel\[$x,$y\]"=>'red'); # Set that pixel red
    }
  shift(@coords);                               # Remove the first entry of the list
  }
$image          ->Write("Cardinal_Spline_Example.png"); # Save image

sub EvaluateCardinal2D
  {
  my($ra_coords,$T,$u)          = @_;
  my $s                         = (1-$T)/2;
  my $u_matrix                  = new Math::Matrix      # 4 x 1
        (                               # Matrix based off the point in the curve
         [($u ** 3),    ($u ** 2),      ($u),           (1)             ]
        );
  my $cardinal_matrix           = new Math::Matrix      # 4 x 4
        (                               # Guts of the Cardinal Spline formula
         [(-1 * $s),    (2 - $s),       ($s - 2),       ($s)            ],
         [(2 * $s),     ($s - 3),       (3-(2 * $s)),   (-1 * $s)       ],
         [(-1 * $s),    (0),            ($s),           (0)             ],
         [(0),          (1),            (0),            (0)             ],
        );
  my $x_matrix                  = new Math::Matrix      # 1 x 4
        (                               # X coords for point:
         [${${$ra_coords}[0]}[0]],      # 1
         [${${$ra_coords}[1]}[0]],      # 2
         [${${$ra_coords}[2]}[0]],      # 3
         [${${$ra_coords}[3]}[0]]       # 4
        );
  my $y_matrix                  = new Math::Matrix      # 1 x 4
        (                               # Y coords for point:
         [${${$ra_coords}[0]}[1]],      # 1
         [${${$ra_coords}[1]}[1]],      # 2
         [${${$ra_coords}[2]}[1]],      # 3
         [${${$ra_coords}[3]}[1]]       # 4
        );
  my $xt        = int ($u_matrix * $cardinal_matrix * $x_matrix); # Compute for X
  my $yt        = int ($u_matrix * $cardinal_matrix * $y_matrix); # Compute for Y
  return($xt,$yt);
  }
 

Licencia

Public domain Yo, el titular de los derechos de autor de esta obra, lo libero al dominio público. Esto aplica en todo el mundo.
En algunos países esto puede no ser legalmente factible; si ello ocurriese:
Concedo a cualquier persona el derecho de usar este trabajo para cualquier propósito, sin ningún tipo de condición al menos que éstas sean requeridas por la ley.

The above source code is released under the same conditions as the image itself. (PD by owner)

Missing from file history: Berland cropped the image 2007-03-05.

Leyendas

Añade una explicación corta acerca de lo que representa este archivo

Elementos representados en este archivo

representa a

a8413cfb6df53fd074f9410ab6a833e8a1d50fa1

480 píxel

720 píxel

Historial del archivo

Haz clic sobre una fecha y hora para ver el archivo tal como apareció en ese momento.

Fecha y horaMiniaturaDimensionesUsuarioComentario
actual00:16 19 dic 2007Miniatura de la versión del 00:16 19 dic 2007720 × 480 (7 kB)HighInBCInstead of cropping an example which uses absolute coordinates, I have moved the curve closer to the edge
21:36 5 mar 2007Miniatura de la versión del 21:36 5 mar 2007563 × 293 (2 kB)Berland
04:35 17 oct 2006Miniatura de la versión del 04:35 17 oct 2006720 × 480 (6 kB)H== Summary == This image is a graphical representation of a ''Cardinal Spline''. It is drawn on a 720x480 canvas and the curve has 10 control points. The tension is set to ''0.1''. The red squares repesent the posistion of the control points, and the red

La siguiente página usa este archivo:

Uso global del archivo

Las wikis siguientes utilizan este archivo: