Encuentra el área del paralelogramo si se dan los vectores de dos lados adyacentes

Dados dos vectores en forma de (xi+yj+zk) de dos lados adyacentes de un paralelogramo. La tarea es encontrar el área de un paralelogramo.
Ejemplo: 
 

Entrada: 
x1 = 3, y1 = 1, z1 = -2 
x2 = 1, y2 = -3, z2 = 4
Salida: Área = 17,3205081 
Entrada: 
x1 = 1, y1 = 3, z1 = 2 
x2 = 1, y2 = -3, z2 = 4
Salida: Área = 19,078784028338912
 

 

Enfoque: supongamos que tenemos dos vectores a(x1*i+y1*j+z1*k) y b(x2*i+y2*j+z2*k) y sabemos que el área del paralelogramo está dada por: 
 

Área del paralelogramo = magnitud del producto vectorial de los vectores a y b, es decir, |axb| 
Y sabemos a X b = (y1*z2 – y2*z1)*i – (x1*z2 – x2*z1)*j + (x1*y2 – x2*y1)*k
Entonces área = 
\hug{\sqrt{(y_{1}*z_{2}-y_{2}*z_{1})^{2}+(x_{1}*z_{2}-x_{2}*z_{1})^{2}+(x_{1}*y_{2}-x_{2}*y_{1})^{2}}

C++

// C++ code to calculate area of
// parallelogram if vectors of
// 2 adjacent sides are given
 
#include<bits/stdc++.h>
using namespace std ;
 
// Function to calculate area of parallelogram 
float area(float x1, float y1, float z1, float x2,
            float y2, float z2)
    {
        float area = sqrt(pow((y1 * z2 - y2 * z1),2)
                        + pow((x1 * z2 - x2 * z1),2) +
                         pow((x1 * y2 - x2 * y1),2));
        return area;
    }
     
// Driver Code
int main()
{
    float x1 = 3;
    float y1 = 1;
    float z1 = -2;
    float x2 = 1;
    float y2 = -3;
    float z2 = 4;
    float a = area(x1, y1, z1, x2, y2, z2);
    cout << "Area = " << a;
    return 0;
// This code is contributed
// by Amber_Saxena.
}

Java

// Java code to calculate area of 
// parallelogram if vectors of
// 2 adjacent sides are given
 
public class GFG {
     
    // Function to calculate area of parallelogram  
    static float area(float x1, float y1, float z1, float x2,
                float y2, float z2)
        { 
            float area =(float) Math.sqrt(Math.pow((y1 * z2 - y2 * z1),2)
                            + Math.pow((x1 * z2 - x2 * z1),2) +
                             Math.pow((x1 * y2 - x2 * y1),2));
            return area;
        } 
 
    // Driver code
    public static void main (String args[]){
         float x1 = 3;
            float y1 = 1;
            float z1 = -2;
            float x2 = 1;
            float y2 = -3;
            float z2 = 4;
            float a = area(x1, y1, z1, x2, y2, z2);
            System.out.println("Area = " + a) ;
           
    }
 
// This code is contributed by ANKITRAI1
}

Python

# Python code to calculate area of
# parallelogram if vectors of
# 2 adjacent sides are given
 
import math
 
# to calculate area of parallelogram
def area(x1, y1, z1, x2, y2, z2):
    area = math.sqrt((y1 * z2 - y2 * z1) ** 2
           + (x1 * z2 - x2 * z1) ** 2 +
           (x1 * y2 - x2 * y1) ** 2)
    return area
 
# main function
def main():
    x1 = 3
    y1 = 1
    z1 = -2
    x2 = 1
    y2 = -3
    z2 = 4
    a = area(x1, y1, z1, x2, y2, z2)
    print("Area = ", a)
 
# driver code   
if __name__=="__main__":
    main()

C#

// C# code to calculate area of
// parallelogram if vectors of
// 2 adjacent sides are given
using System;
 
class GFG
{
 
// Function to calculate area
// of parallelogram
static float area(float x1, float y1,
                  float z1, float x2,
                  float y2, float z2)
{
    float area = (float) Math.Sqrt(Math.Pow((y1 * z2 - y2 * z1), 2) +
                                   Math.Pow((x1 * z2 - x2 * z1), 2) +
                                   Math.Pow((x1 * y2 - x2 * y1), 2));
    return area;
}
 
// Driver code
public static void Main ()
{
    float x1 = 3;
    float y1 = 1;
    float z1 = -2;
    float x2 = 1;
    float y2 = -3;
    float z2 = 4;
    float a = area(x1, y1, z1, x2, y2, z2);
    Console.Write("Area = " + a) ;
}
}
 
// This code is contributed
// by ChitraNayal

PHP

<?php
// PHP code to calculate area of
// parallelogram if vectors of
// 2 adjacent sides are given
 
// Function to calculate area
// of parallelogram
function area($x1, $y1, $z1,
              $x2, $y2, $z2)
{
        $area = sqrt(pow(($y1 * $z2 - $y2 * $z1), 2) +
                     pow(($x1 * $z2 - $x2 * $z1), 2) +
                     pow(($x1 * $y2 - $x2 * $y1), 2));
        return $area;
}
     
// Driver Code
$x1 = 3; $y1 = 1; $z1 = -2;
$x2 = 1; $y2 = -3; $z2 = 4;
$a = area($x1, $y1, $z1,
          $x2, $y2, $z2);
echo ("Area = ");
echo ($a);
     
// This code is contributed
// by Shivi_Aggarwal
?>

Javascript

<script>
 
// Javascript code to calculate area of
// parallelogram if vectors of
// 2 adjacent sides are given
 
// Function to calculate area
// of parallelogram
function area(x1, y1, z1,
              x2, y2, z2)
{
        area = Math.sqrt(Math.pow((y1 * z2 - y2 * z1), 2) +
                     Math.pow((x1 * z2 - x2 * z1), 2) +
                     Math.pow((x1 * y2 - x2 * y1), 2));
        return area;
}
     
// Driver Code
let x1 = 3;
let y1 = 1;
let z1 = -2;
let x2 = 1;
let y2 = -3;
let z2 = 4;
a = area(x1, y1, z1,
          x2, y2, z2);
document.write ("Area = ");
document.write (a);
     
// This code is contributed by Bobby
 
</script>
Producción: 

Area =  17.320508075688775

 

Complejidad de tiempo: O(1)

Espacio Auxiliar: O(1)

Publicación traducida automáticamente

Artículo escrito por AashutoshChauhan y traducido por Barcelona Geeks. The original can be accessed here. Licence: CCBY-SA

Deja una respuesta

Tu dirección de correo electrónico no será publicada. Los campos obligatorios están marcados con *