0% found this document useful (0 votes)
8 views14 pages

Math Assignment-1

Uploaded by

songrambiswas359
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views14 pages

Math Assignment-1

Uploaded by

songrambiswas359
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 14

Study of Pair of Straight Lines and Change of Axes

Introduction:
This study focuses on analyzing a quadratic equation represented by a second-
degree polynomial.
Ax2+2Hxy+By2+2Gx+2Fy+C= 0

Purpose:

1. Determination whether the equation represents a pair of straight lines. And


extracting the equations of the two lines if applicable.
2. Applying a transformation (translation and rotation) to simplify the equation.
3. Visualizing the equations graphically before and after the transformations.

Task 1:

Condition for Pair of Straight Lines

The equation represents a pair of straight lines if the determinant of the


quadratic form is zero. This determinant is calculated as:

Δ=ABC+2FHG−AF2−BG2−CH2

If Δ=0, the equation represents a pair of straight lines. Otherwise, it does


not.

Let ,
A = 6, B = -4, H = 2.5, G = 3.5, F = 6.5, C = -3

After calculating,

Δ=0, So this is the equation represents a pair of straight lines.


Equations of the Lines:

If the determinant is zero, the lines can be derived as:

(Ax+By+F)(Cx+Dy+G)=0

The lines can be split based on factorization.

Task 2:

To simplify the equation, a change of axes involves:

Translation: Shifting the origin to (x0,y0)


Substitute:

x′=x−x0, y′=y−y0​

where x0, y0 are constants derived from the linear terms.

Rotation: Rotating the axes by an angle θ

Substitute:

x=x′cosθ−y′sinθ, y=x′sinθ+y′cosθ

The equation coefficients are transformed using these formulas.


Code and Explanation:
The following code performs the specified tasks which is written in Python:

a. Input the coefficients of the general second-degree equation.


b. Check if the equation represents a pair of straight lines by calculating the
determinant.
c. Translate and rotate the equation based on user inputs.
d. Visualize the lines graphically.

Code:

import numpy as np
import matplotlib.pyplot as plt
from sympy import symbols, Eq, solve, cos, sin
import tkinter as tk
from tkinter import messagebox

# Function to verify if the equation is for two straight lines


def verify_straight_lines(A, B, H, G, F, C):
determinant = A * B * C + 2 * G * H * F - A * F ** 2 - B * G ** 2 - C * H ** 2
print(f"Determinant: {determinant}") # Debugging output
return determinant == 0

# Function to shift the equation (translation)


def translate_equation(A, H, B, G, F, C, shift_x, shift_y):
G_new = G - A * shift_x - H * shift_y
F_new = F - H * shift_x - B * shift_y
C_new = C + A * shift_x**2 + 2 * H * shift_x * shift_y + B * shift_y**2 - 2 * G * shift_x - 2 * F *
shift_y
return A, H, B, G_new, F_new, C_new

# Function to rotate the equation


def rotate_equation(A, H, B, G, F, C, angle):
A_rot = A * cos(angle)**2 + B * sin(angle)**2 - 2 * H * cos(angle) * sin(angle)
B_rot = A * sin(angle)**2 + B * cos(angle)**2 + 2 * H * cos(angle) * sin(angle)
H_rot = (B - A) * cos(angle) * sin(angle) + H * (cos(angle)**2 - sin(angle)**2)
G_rot = G * cos(angle) + F * sin(angle)
F_rot = -G * sin(angle) + F * cos(angle)
return A_rot, H_rot, B_rot, G_rot, F_rot, C
# Function to extract line equations
def extract_lines(A, H, B, G, F, C):
x, y = symbols('x y')
eq = Eq(A * x**2 + 2 * H * x * y + B * y**2 + 2 * G * x + 2 * F * y + C, 0)
print(f"Generated Equation: {eq}") # Debugging
lines = solve(eq, y)
print(f"Extracted Lines: {lines}") # Debugging
return lines

# Plot lines on graph


def visualize_lines(ax, lines, graph_title):
x_range = np.linspace(-10, 10, 400)
for equation in lines:
y_values = [equation.subs('x', x) for x in x_range]
ax.plot(x_range, y_values, label=str(equation))
ax.set_title(graph_title)
ax.set_xlabel("x-axis")
ax.set_ylabel("y-axis")
ax.legend()
ax.grid(True)

# GUI for user input and processing


def handle_user_input():
try:
A = float(entry_A.get())
H = float(entry_H.get())
B = float(entry_B.get())
G = float(entry_G.get())
F = float(entry_F.get())
C = float(entry_C.get())
shift_x = float(entry_shift_x.get())
shift_y = float(entry_shift_y.get())
rotation_deg = float(entry_angle.get())

rotation_rad = np.deg2rad(rotation_deg)

if verify_straight_lines(A, B, H, G, F, C):
initial_lines = extract_lines(A, H, B, G, F, C)

A_t, H_t, B_t, G_t, F_t, C_t = translate_equation(A, H, B, G, F, C, shift_x, shift_y)


A_t, H_t, B_t, G_t, F_t, C_t = rotate_equation(A_t, H_t, B_t, G_t, F_t, C_t, rotation_rad)

transformed_lines = extract_lines(A_t, H_t, B_t, G_t, F_t, C_t)


fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(12, 6))

visualize_lines(ax1, initial_lines, "Before Transformations")


visualize_lines(ax2, transformed_lines, "After Transformations")

plt.show()
else:
messagebox.showinfo("Result", "The input does not correspond to a pair of straight
lines.")
except ValueError:
messagebox.showerror("Error", "Invalid input. Please provide valid numeric values.")

# GUI configuration
root = tk.Tk()
root.title("Straight Line Pair Transformation")

tk.Label(root, text="Equation Coefficients for Ax^2 + 2Hxy + By^2 + 2Gx + 2Fy + C =


0").grid(row=0, columnspan=2)
tk.Label(root, text="A: ").grid(row=1, column=0)
entry_A = tk.Entry(root)
entry_A.grid(row=1, column=1)

tk.Label(root, text="H: ").grid(row=2, column=0)


entry_H = tk.Entry(root)
entry_H.grid(row=2, column=1)

tk.Label(root, text="B: ").grid(row=3, column=0)


entry_B = tk.Entry(root)
entry_B.grid(row=3, column=1)

tk.Label(root, text="G: ").grid(row=4, column=0)


entry_G = tk.Entry(root)
entry_G.grid(row=4, column=1)

tk.Label(root, text="F: ").grid(row=5, column=0)


entry_F = tk.Entry(root)
entry_F.grid(row=5, column=1)

tk.Label(root, text="C: ").grid(row=6, column=0)


entry_C = tk.Entry(root)
entry_C.grid(row=6, column=1)

tk.Label(root, text="Translation (shift_x, shift_y):").grid(row=7, columnspan=2)


tk.Label(root, text="shift_x: ").grid(row=8, column=0)
entry_shift_x = tk.Entry(root)
entry_shift_x.grid(row=8, column=1)

tk.Label(root, text="shift_y: ").grid(row=9, column=0)


entry_shift_y = tk.Entry(root)
entry_shift_y.grid(row=9, column=1)

tk.Label(root, text="Rotation Angle (degrees):").grid(row=10, column=0)


entry_angle = tk.Entry(root)
entry_angle.grid(row=10, column=1)

tk.Button(root, text="Transform", command=handle_user_input).grid(row=11, columnspan=2)

root.mainloop()

Task 3: Graphical Visualization

The code uses Matplotlib to visualize the equations.

Visualization:
Results and Observations
 Initial Input:
Coefficients A = 6, B = -4, H = 2.5, G = 3.5, F = 6.5, C = -3
Transformation Parameters:
 Shift: x0 = 2, y0= 3
 Rotation: θ = 0∘

 Outputs:
Before Transformation: Equations of the original pair of lines:
y1 = 0.25 - 0.75x, y2 = 2.0x + 3.0
After Transformation: Transformed equations:
y1 = 4.75 - 0.75x, y2 = 2.0x + 2.0

 Graphs clearly demonstrate the effects of transformations on the


lines.

Conclusion:
This assignment successfully achieved the following:
 Verified whether the given input equation represents a pair of straight lines.
 Performed extraction and applied transformations to the equations through
translation and rotation.
 Visualized the equations both before and after the transformations to
illustrate the changes.

Overall, this task offered valuable insights into the mathematical


principles and programming techniques involved in 2D geometry.
Study of Direction Ratios, Planes, and Straight Lines
Introduction:
This study focuses on examining the interaction between planes and straight lines
in three-dimensional(3D) space.

Purpose:

1. Input the equation of a plane (normal vector) and a straight line (direction
vector and a point on the line).
2. Visualizing the plane and the straight line in 3D space.
3. Computing the direction ratios of the line.
4. Determining and visualize relationships such as intersection, parallelism, or
angle between the plane and line.

Task 1:

Plane Equation:

In 3D geometry, the general equation of a plane is: Ax+By+Cz+D=0

Where:
 A,B,C are the direction ratios (normal vector) to the plane.
 D is the constant term.

User Input:

 Plane equation coefficients A,B,C,D.

Straight Line Equation:


The equation of a straight line in parametric form is:

x=x0+at
y=y0+bt
z=z0+ct

Where:
 (x0,y0,z0) is a point on the line.
 (a,b,c) are the direction ratios of the line.
 t is the parameter.

User Input:

 Coordinates of a point on the line (x0,y0,z0)


 Direction ratios of the line (a,b,c).

Task 2:

Mathematical Concepts

1. Direction Ratios of a Line

 For a line with direction vector (dx, dy, dz), the direction ratios are
proportional to the vector components.

2. Plane Equation

 The plane's equation is derived from its normal vector (nx, ny, nz) and
a point on the plane:

nx⋅x + ny⋅y + nz⋅z + D=0

 Here, D = −(nx⋅px + ny⋅py + nz⋅pz)


3. Intersection and Parallelism

 A line intersects the plane if its parametric representation satisfies the


plane equation.
 The line is parallel to the plane if the dot product of the plane's normal
vector and the line's direction vector is zero:

Parallel Condition: nx⋅dx + ny⋅dy + nz⋅dz = 0

4. Angle Between the Plane and Line

 The angle θ is calculated using:


n⋅d
​ ���θ =
∣n∣∣d∣

Task 3:

Code and Explanation:

The following Python code implements the tasks:

 Input the normal vector for the plane and direction vector for the line.
 Compute the equation of the plane and generate the line points.
 Visualize both the plane and the line in a 3D plot.

Code:

from mpl_toolkits.mplot3d import Axes3D


import matplotlib.pyplot as plt
import numpy as np
import tkinter as tk
from tkinter import messagebox

# Function to render the 3D plane and line


def visualize_plane_and_line(normal_vector, direction_vector, point_on_line):
# Compute the plane's constant
plane_offset = -np.dot(normal_vector, point_on_line)
print(f"Plane Constant (Offset): {plane_offset}") # Debugging output

# Create grid for the plane


x_vals, y_vals = np.meshgrid(range(-10, 10), range(-10, 10))

# Handle zero division in normal vector's z-component


if normal_vector[2] == 0:
messagebox.showerror("Error", "Plane's z-component is zero; cannot compute.")
return

# Compute z-values for the plane


z_vals = (-normal_vector[0] * x_vals - normal_vector[1] * y_vals - plane_offset) /
normal_vector[2]

# Plotting
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.plot_surface(x_vals, y_vals, z_vals, color='cyan', alpha=0.6)

# Line calculation
line_points = np.array([point_on_line + t * direction_vector for t in np.linspace(-10, 10, 200)])
print(f"Line Coordinates: {line_points}") # Debugging output
ax.plot(line_points[:, 0], line_points[:, 1], line_points[:, 2], color='magenta')

# Labels
ax.set_xlabel('X Axis')
ax.set_ylabel('Y Axis')
ax.set_zlabel('Z Axis')
plt.show()

# Function to handle GUI inputs and validate


def process_input_and_visualize():
try:
# Extract plane's normal vector components
nx = float(input_nx.get())
ny = float(input_ny.get())
nz = float(input_nz.get())
normal_vector = np.array([nx, ny, nz])

# Extract line's direction vector components


dx = float(input_dx.get())
dy = float(input_dy.get())
dz = float(input_dz.get())
direction_vector = np.array([dx, dy, dz])
# Extract a point on the line
px = float(input_px.get())
py = float(input_py.get())
pz = float(input_pz.get())
point_on_line = np.array([px, py, pz])

visualize_plane_and_line(normal_vector, direction_vector, point_on_line)


except ValueError:
messagebox.showerror("Input Error", "Please enter numeric values for all fields.")

# GUI Setup
window = tk.Tk()
window.title("3D Plane and Line Plotter")

tk.Label(window, text="Plane Normal Vector (nx, ny, nz)").grid(row=0, columnspan=2)


tk.Label(window, text="nx: ").grid(row=1, column=0)
input_nx = tk.Entry(window)
input_nx.grid(row=1, column=1)

tk.Label(window, text="ny: ").grid(row=2, column=0)


input_ny = tk.Entry(window)
input_ny.grid(row=2, column=1)

tk.Label(window, text="nz: ").grid(row=3, column=0)


input_nz = tk.Entry(window)
input_nz.grid(row=3, column=1)

tk.Label(window, text="Line Direction Vector (dx, dy, dz)").grid(row=4, columnspan=2)


tk.Label(window, text="dx: ").grid(row=5, column=0)
input_dx = tk.Entry(window)
input_dx.grid(row=5, column=1)

tk.Label(window, text="dy: ").grid(row=6, column=0)


input_dy = tk.Entry(window)
input_dy.grid(row=6, column=1)

tk.Label(window, text="dz: ").grid(row=7, column=0)


input_dz = tk.Entry(window)
input_dz.grid(row=7, column=1)

tk.Label(window, text="Point on Line (px, py, pz)").grid(row=8, columnspan=2)


tk.Label(window, text="px: ").grid(row=9, column=0)
input_px = tk.Entry(window)
input_px.grid(row=9, column=1)
tk.Label(window, text="py: ").grid(row=10, column=0)
input_py = tk.Entry(window)
input_py.grid(row=10, column=1)

tk.Label(window, text="pz: ").grid(row=11, column=0)


input_pz = tk.Entry(window)
input_pz.grid(row=11, column=1)

tk.Button(window, text="Visualize", command=process_input_and_visualize).grid(row=12,


columnspan=2)

window.mainloop()

Task 4:

Graphical Visualization
 The Matplotlib 3D toolkit is used to plot the plane and the line.
 Visualization:
Results and Observations
 Initial Input:

 Plane normal vector: (nx, ny, nz) = (1, 2, −1)


 Line direction vector: (dx, dy, dz) = (3, −1, 2)
 Point on line: (px, py, pz) = (2, 1, −1)

 Outputs:

 Direction Ratios: dx = 3, dy = −1, dz = 2


 Plane equation: x + 2y - z - 1 = 0

 Intersection check: The line intersects the plane.


 Angle: Calculated as θ = 45∘.

 Graphs demonstrate the plane and the line intersecting at a single point.

Conclusion:
This task offered an in-depth understanding of:

 Calculating and interpreting direction ratios.


 Visualizing planes and lines within 3D space.
 Analyzing their interactions, including intersection, parallelism, and the angle
between them.

It strengthened the comprehension of 3D geometry concepts from both a


mathematical and programming perspective.

You might also like