
- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Find area of triangle if two vectors of two adjacent sides are given using C++
Suppose we have two vectors for two adjacent sides of a triangle in the form $x\hat{i}+y\hat{j}+z\hat{k}$ Our task is to find the area of triangle. The area of triangle is magnitude of the cross product of two vectors. (|A x B|)
$$\frac{1}{2}\rvert \vec{A}\times\vec{B}\rvert=\frac{1}{2}\sqrt{\lgroup y_{1}*z_{2}-y_{2}*z_{1}\rgroup^{2}+\lgroup x_{1}*z_{2}-x_{2}*z_{1}\rgroup^{2}+\lgroup x_{1}*y_{2}-x_{2}*y_{1}\rgroup^{2}}$$
Example
#include<iostream> #include<cmath> using namespace std; float area(float A[], float B[]) { float area = sqrt(pow((A[1] * B[2] - B[1] * A[2]),2) + pow((A[0] * B[2] - B[0] * A[2]),2) + pow((A[0] * B[1] - B[0] * A[1]),2)); return area*0.5; } int main() { float A[] = {3, 1, -2}; float B[] = {1, -3, 4}; float a = area(A, B); cout << "Area = " << a; }
Output
Area = 8.66025
- Related Questions & Answers
- Find area of parallelogram if vectors of two adjacent sides are given using C++.
- Find the hypotenuse of a right angled triangle with given two sides in C++
- Find other two sides of a right angle triangle in C++
- Golang Program to Find the Area of a Triangle Given All Three Sides
- Find other two sides and angles of a right angle triangle in C++
- Calculating the area of a triangle using its three sides in JavaScript
- C++ program to find the Area of the circumcircle of any triangles with sides given?
- Area of the circumcircle of any triangles with sides given in C++
- Check whether triangle is valid or not if sides are given in Python
- Find if two rectangles overlap using C++.
- Check if two strings are anagram of each other using C++
- Check if two given sets are disjoint?
- How to find the union of two vectors in R?
- C++ Program to Compute Cross Product of Two Vectors
- Area of Reuleaux Triangle?
Advertisements