Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Apprendre Défi : Transformations Linéaires des Figures | Algèbre Linéaire
Mathématiques pour l'Analyse de Données et la Modélisation

book
Défi : Transformations Linéaires des Figures

Tâche

Swipe to start coding

Les transformations linéaires des figures sont couramment utilisées en infographie. Il existe 2 principaux types de transformations linéaires :

  1. Transformation de rotation qui fait pivoter une figure autour d'un point ou d'un axe spécifique.
  2. Transformation d'échelle qui redimensionne une figure en modifiant sa taille le long de chaque axe.

Votre tâche est d'appliquer toutes ces transformations à un rectangle une par une. En conséquence, nous aurons une composition de transformations :

  1. Créez une matrice de rotation qui fait pivoter une figure de np.pi / 3 degrés.
  2. Créez une matrice de mise à l'échelle avec les paramètres scale_x = 2 et scale_y = 0.5.
  3. Appliquez la rotation_matrix au carré.
  4. Appliquez la scaling_matrix au résultat de la transformation précédente.

Solution

import numpy as np
import matplotlib.pyplot as plt

# Function to construct a rotation matrix
def rotation_matrix(angle):
cos_theta = np.cos(angle)
sin_theta = np.sin(angle)
return np.array([[cos_theta, -sin_theta],
[sin_theta, cos_theta]])

# Function to construct a scaling matrix
def scaling_matrix(scale_x, scale_y):
return np.array([[scale_x, 0],
[0, scale_y]])

# Function to plot a square
def plot_square(square, color):
square = np.vstack((square, square[0])) # Close the square by repeating the first point
plt.plot(square[:, 0], square[:, 1], color=color)

# Define a square using its corners as a matrix
square = np.array([
[0, 0],
[1, 0],
[1, 1],
[0, 1],
[0, 0] # Close the square
]).T # Transpose to have x and y as separate rows

# Plot the original square
plot_square(square.T, 'blue')

# Define the rotation angle and scaling factors
angle = np.pi / 3
scale_x, scale_y = 2, 0.5

Tout était clair ?

Comment pouvons-nous l'améliorer ?

Merci pour vos commentaires !

Section 2. Chapitre 5
single

single

import numpy as np
import matplotlib.pyplot as plt

# Function to construct a rotation matrix
def rotation_matrix(angle):
cos_theta = np.cos(angle)
sin_theta = np.sin(angle)
return np.array([[cos_theta, -sin_theta],
[sin_theta, cos_theta]])

# Function to construct a scaling matrix
def scaling_matrix(scale_x, scale_y):
return np.array([[scale_x, 0],
[0, scale_y]])

# Function to plot a square
def plot_square(square, color):
square = np.vstack((square, square[0])) # Close the square by repeating the first point
plt.plot(square[:, 0], square[:, 1], color=color)

# Define a square using its corners as a matrix
square = np.array([
[0, 0],
[1, 0],
[1, 1],
[0, 1],
[0, 0] # Close the square
]).T # Transpose to have x and y as separate rows

# Plot the original square
plot_square(square.T, 'blue')

# Define the rotation angle and scaling factors
angle = ___
scale_x, scale_y = ___, ___

Demandez à l'IA

expand

Demandez à l'IA

ChatGPT

Posez n'importe quelle question ou essayez l'une des questions suggérées pour commencer notre discussion

some-alt