You are on page 1of 4

Cornerstone of Engineering

To: Professor Richard Whalen

From: Alim Nurmamedov

MATLAB Homework 4

04.01.2019

Table of Contents
Part 1.................................................................................................................................2
m-file: DMS_TO_RAD...................................................................................................................2
m-file: Next_Coord()....................................................................................................................2
m-file............................................................................................................................................2
Results.........................................................................................................................................3
Extra Credit........................................................................................................................3
m-file............................................................................................................................................3
Letter.................................................................................................................................4
Part 1
m-file: DMS_TO_RAD
function degrees = DMS_to_RAD (deg, min, sec)
degrees = (deg+min/60+ sec/360)*2*pi/360;
end 

m-file: Next_Coord()
function coord = Next_Coord(coord0,azimuth0, distance0)
coord = [0,0]
coord(1,1) = coord0(1,1)+distance0.*sin(azimuth0)
coord(1,2)= coord0(1,2)+distance0.*cos(azimuth0)
end

m-file
%Alim Nurmamedov 
%03.30.19
%This program will calculate the coordinates of points on the given plot
%using functions 
 
%First point:
degr = DMS_to_RAD(44,26,29);%calling function to translate degrees into radians 
azimuth = 2*pi - degr; %find azimuth 
coord1 = [0 0];% coord of the first point 
dist= 32.45; %distance 
cor1 = Next_Coord(coord1, azimuth,dist);
fileid = fopen('HW_41_Results','w');
fprintf(fileid,'First coordinates are (%f, %f)\n\n', cor1)
coord1 = cor1; 
 
%Second coord
degr = DMS_to_RAD(57,21,14);%calling function to translate degrees into radians 
azimuth =  degr; %find azimuth 
%coord1 = [0 0];% coord of the first point 
dist= 63.87; %distance 
cor2 = Next_Coord(coord1, azimuth,dist);
fprintf(fileid,'Second coordinates are (%f, %f)\n\n', cor2)
coord1 = cor2; 
 
%Third coord 
degr = DMS_to_RAD(85,43,32);%calling function to translate degrees into radians 
azimuth = pi- degr; %find azimuth 
%coord1 = [0 0];% coord of the first point 
dist= 55.1; %distance 
cor3 = Next_Coord(coord1, azimuth,dist);
 
fprintf(fileid,'Third coordinates are (%f, %f)\n\n', cor3)
coord1 = cor3; 
 
%Fourth coord
degr = DMS_to_RAD(15,52,07);%calling function to translate degrees into radians 
azimuth = pi- degr; %find azimuth 
%coord1 = [0 0];% coord of the first point 
dist= 18.74; %distance 
cor4 = Next_Coord(coord1, azimuth,dist);
 
fprintf(fileid,'Fourth coordinates are (%f, %f)\n\n', cor4)
coord1 = cor4;  
 
%Fifth coord
degr = DMS_to_RAD(25,19,47);%calling function to translate degrees into radians 
azimuth =pi+ degr %find azimuth 
%coord1 = [0 0];% coord of the first point 
dist= 12.8; %distance 
cor5 = Next_Coord(coord1, azimuth,dist);
fprintf(fileid,'Fifth coordinates are (%f, %f)\n\n', cor5)
coord1 = cor5; 
 
%Find distance between points A and B and bearing in deg from north
coordB = cor5; %coordinate B is the fifth coordinate assigned as cor 
distanceAB =hypot(coordB(1,1),coordB(1,2));% find distance using hypot() function
fprintf(fileid,'Distance between A and B = %f\n\n', distanceAB);
beardeg = (pi/2 - atan(coordB(1,2)/coordB(1,1)))*360/(2*pi);
fprintf(fileid,'Bearing in degrees from north %f\n\n', beardeg);
%Find the area of polygon 
p = [0,0; cor1; cor2; cor3;cor4;cor5; 0,0];% create an array of coordinate x in columns and coordinate y in rows
x = p(:,1);%array of x coordinates
y= p(:,2);%array of y coordinates
area = polyarea(x,y);%find the area of polygon using polyarea() function
fprintf(fileid,'Area of polygon =  %f acrs\n\n', area);

Results
First coordinates are (-22.750115, 23.139463)
 
Second coordinates are (31.050645, 57.561187)
 
Third coordinates are (86.003064, 53.531091)
 
Fourth coordinates are (91.132690, 35.506815)
 
Fifth coordinates are (85.632793, 23.948652)
 
Distance between A and B = 88.918576
 
Bearing in degrees from north 74.375456
 
Area of polygon =  3999.531269 acrs

Extra Credit
m-file
% Alim Nurmamedov
%04.04.2019
%This program will automatically calculate bearing, distance and area under
%given polygon
  i=1; %array counter
  j=2; %X and Y array counter
  X = 0; 
  Y = 0; 
N = 1;
X(1) = input('Enter Initial X Corrdinate: '); %enter first coord x
Y(1) = input('Enter Initial Y Coordinate: ');% 
coordinateXY = [X(1),Y(1)];
%while loop to collect the data
while (N==1)  
dist = input('Enter Distance of Leg: '); 
bear = input('Enter Bearing in [Degrees Minutes Seconds]: ');
direct = input('Enter 1,2,3 or 4 for NW NE SE SW Bearing: ');
degr = DMS_to_RAD(bear(1,1),bear(1,2),bear(1,3)); %convert entered degrees into radians 
 
% if functions to identify the right angle to use 
if (direct == 1) %NW
    azimuth(i) = 2*pi - degr;
end
if (direct == 2) %NE
    azimuth(i) = degr;
end
if (direct == 3) %SE
    azimuth(i) = pi - degr;
end
if(direct == 4) %SW
    azimuth(i) = pi+degr;
end 
 
%end of if functions 
cord  = Next_Coord(coordinateXY,azimuth(i), dist);% call function Next_Coord()
X(j) = cord (1,1); 
Y(j) = cord (1,2);
coordinateXY = [X(j),Y(j)];% Put x and y into array to use in function Next_Coord()
i= i+1;
j= j+1;
N = input('Enter 1 for another side or 2 to calculate: ');
 
end
 
 
distance = sqrt(X(j-1)^2 +Y(j-1)^2);
area = polyarea(X,Y);
fileid = fopen ('Extra_Credit_HW41_results','w');
fprintf (fileid, 'Area of a polygon = %f \n\n', area);
fprintf(fileid, 'X: %f     Y:%f  \n\n', X, Y);
 
%If functions to find North azimuth angle for bearing 
 
 
if (X(j-1) >X(1) && Y(j-1) > Y(1)) 
 angle = 90 - atan (Y(j-1)/X(j-1))*180/pi;
end
 
if (X(j-1) < X(1) && Y(j-1) > Y(1)) 
 angle = 270 +  atan (Y(j-1)/X(j-1))*180/pi;
end
 
 
if (X(j-1) >X(1) && Y(j-1) < Y(1)) 
 angle = 90 + atan (Y(j-1)/X(j-1))*180/pi;
end
 
 
if (X(j-1) < X(1) && Y(j-1) < Y(1)) 
 angle = 270 - atan (Y(j-1)/X(j-1))*180/pi;
end
 
%print azimuth and bearing
fprintf(fileid, 'The bearing from A to B is %f degrees from North Azimuth\n\n' , angle); 
fprintf(fileid,'The distance along QUAKER STREET from B to A is %f', distance); 

Letter
To: Mr. Rich Guy
From: Alim Nurmamedov

Dear Mr. Rich Guy,

I am writing to let you know that I have wrote a program that calculates the area of your
property on Quaker Street. It equals to almost 4000 acres.
Our analysis revealed that the distance between point A and B is equal to 89 ft and the
incline of AB from the horizontal line is 16 degrees.

If you want to make sure that the calculation is right or if you would like to calculate any
other area, I added the program to the attachments, where you can do your own
measurements.

Best regards,
Alim Nurmamedov

You might also like