Question
In CAD application finding intersections of lines and geometric property of triangles (e.g., area and centroid) in a plane are often required. A line can
In CAD application finding intersections of lines and geometric property of triangles (e.g., area and centroid) in a plane are often required. A line can be represented by a linear equation: + = The coefficients a, b, c define a line uniquely, so the triplet (a, b, c) can be used to specify any line. Thus (a1, b1, c1) and (a2, b2, c2) represent two lines and intersection of them can be calculated by solution to the system of two linear equations.
Three lines, in general, fix a triangle whose vertices are intersections of two lines. Let the point coordinates of the three vertices be (x1, y1) (x2, y2), and (x3, y3) for the triangle, the following geometric properties can be calculated:
Centroid = [ ] = [ 1 3 (1 + 2 + 3) 1 3 (1 + 2 + 3) ]
Area = 1 2 | 1(2 3) + 2(3 1) + 3(1 2) |
a) Write a Matlab function program to calculate the x, y coordinates of intersection point given two lines defined by coefficient sets L1 = [a1, b1, c1] and L2 = [a2, b2, c2]. That is, the function inputs are the coefficients specifying the two lines, and function output are the coordinates of the intersection point. Define your function as YourNameIntersection in the following format: [x, y] = YourNameIntersection (L1, L2)
b) Write a Matlab script program to compute the centroid and the area of a triangle fixed by three given lines. Your program should prompt the user to input the three line coefficients and display the centroid coordinates and the area as the output upon execution. It is suggested that you use the function you created in part (a) to produce the intersection points of three lines. Name your script file as YourName. Test your program using the following line coefficient data (a, b, c): Line 1: [2, 3, 1], Line 2: [1,-2, 4] Line 3: [5, 1, 0]
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started