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

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 views10 pages

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/ 10

Study of Pair of Straight Lines and Change of Axes

Introduction

This study involves analyzing a second-degree equation of the form:

Ax2+2Hxy+By2+2Gx+2Fy+C= 0

Purpose:

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


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

Code and Explanation

The following Python code performs the specified tasks:

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


 Check if the equation represents a pair of straight lines by calculating the determinant.
 Translate and rotate the equation based on user inputs.
 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()

Mathematical Concepts

1. Determination of Pair of Straight Lines

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

Δ=A.B⋅C+2GHF−AF2−BG2−CH2=0

2. Equation Transformation

Translation: Shifts the graph using new coordinates:

x′=x−shiftx, y′=y−shifty

Rotation: Rotates the graph by an angle θ:

x′=xcosθ+ysinθ, y′=xsinθ-ycosθ
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: shiftx = 2, shifty = 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

The assignment successfully implemented:

 Verification of whether the input equation represents a pair of straight lines.


 Extraction and transformation of the equations using translation and rotation.
 Visualization of the changes in the equations before and after transformations.

This task provided insights into the mathematical and programming aspects of 2D geometry.
Study of Direction Ratios, Planes, and Straight Lines

Introduction

This task involves analyzing the relationship between planes and straight lines in 3D space. The
objectives are:

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.

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()
Mathematical Concepts

1. Direction Ratios of a Line


o For a line with direction vector (dx, dy, dz), the direction ratios are proportional to the
vector components.
2. Plane Equation
o 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

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


3. Intersection and Parallelism
o A line intersects the plane if its parametric representation satisfies the plane equation.
o 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


o The angle θ is calculated using:

n⋅d
𝐜𝐨𝐬θ =
∣n∣∣d∣

Graphical Visualization

 The Matplotlib 3D toolkit is used to plot the plane and the line.
 Visualization:
Results and Observations

 Initial Input:
o Plane normal vector: (nx, ny, nz) = (1, 2, −1)
o Line direction vector: (dx, dy, dz) = (3, −1, 2)
o Point on line: (px, py, pz) = (2, 1, −1)
 Outputs:
o Direction Ratios: dx = 3, dy = −1, dz = 2
o Plane equation:

x + 2y - z - 1 = 0

o Intersection check: The line intersects the plane.


o Angle: Calculated as θ = 45∘.
 Graphs demonstrate the plane and the line intersecting at a single point.

Conclusion

This task provided a comprehensive understanding of:

 Computing and interpreting direction ratios.


 Visualizing planes and lines in 3D space.
 Analyzing their relationships (intersection, parallelism, and angle).
This enhances the grasp of 3D geometry concepts both mathematically and programmatically.

You might also like