Solving Questions related to 3-D triangles

5 Ansichten (letzte 30 Tage)
Max Altshuler
Max Altshuler am 16 Apr. 2019
Kommentiert: Matt J am 23 Apr. 2019
Given 3 points in space write a function or functions that will find:
(a) the distance between each of the points
(b) find the angle of each of the verticies making up the triangle
(c) area of the triangle.
Ask for each of the points using the input command,
The input will be 3 points A = (x1,y1,z1), B = (x2,y2,x2), and C = (x3,y3,z3). Figure out a way to check your answer.
A = [10 6 -9]; % three verticies
B = [5 -8 1];
C = [-4 6 -2];
[AB,BC,CA] = FindDistance(A,B,C)
[A1,B1,C1] = FindAngles(AB,BC,CA)
[Area] = FindTriangleArea(AB,BC,CA,A1)
Functions
function [AB,BC,CA] = FindDistance(A,B,C)
% distance between of line segments between the points
AB1 = B-A; % finds length difference in each direction
BC1 = C-B;
CA1 = A-C;
AB = sqrt(sum(dot(AB1,AB1))); % finds magnitude of line segment
BC = sqrt(sum(dot(BC1,BC1)));
CA = sqrt(sum(dot(CA1,CA1)));
end
function [A1,B1,C1] = FindAngles(AB,BC,CA)
% find angles between to connected lines
B1 = acosd(BC/AB);
A1 = acosd(CA/AB);
C1 = 180-B1-A1;
end
function [Area] = FindTriangleArea(AB,BC,CA,A1)
% find area of triangle with only side length
b = AB;
h = CA*sind(A1)
Area = (1/2)*b*h
end
Our instructor gave us predetermined verticies. I am having a lot of trouble with finding the angles and finding the area of the triangle. My function that finds the length of each side works perfectly, but I can not seem to figure out why my other two functions are not working. I'm assuming my Area function is wrong because my Angle function is wrong.
Anyways, if anyone can edit my code and give a breif explanation on why its wrong that would be great. Any help will be great, you do not have to go through and edit everything, just one fix will help.
Also, if you can find already pre-made functions that I can look at to help me write my own, please paste the link in this thread.
Thank you so much!!!
  3 Kommentare
Max Altshuler
Max Altshuler am 23 Apr. 2019
I still can not seem to get it. My angles keep showing up as imaginary. Have any ideas?
Matt J
Matt J am 23 Apr. 2019
I still can not seem to get it
Please show us your implementation of darova's suggestions, so that we can try to see what is wrong.

Melden Sie sich an, um zu kommentieren.

Antworten (0)

Kategorien

Mehr zu Computational Geometry finden Sie in Help Center und File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by