Skip to content

Instantly share code, notes, and snippets.

@chuongmep
Last active May 13, 2021 03:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chuongmep/ed68b78b6072a8865121a5348d5a6a09 to your computer and use it in GitHub Desktop.
Save chuongmep/ed68b78b6072a8865121a5348d5a6a09 to your computer and use it in GitHub Desktop.
/// <summary>
/// Cross Product Vector
/// </summary>
/// <param name="vector"></param>
/// <param name="other"></param>
/// <returns></returns>
public static Autodesk.DesignScript.Geometry.Vector Cross(Autodesk.DesignScript.Geometry.Vector vector,
Autodesk.DesignScript.Geometry.Vector other)
{
var x = vector.Y * other.Z - vector.Z * other.Y;
var y = vector.Z * other.X - vector.X * other.Z;
var z = vector.X * other.Y - vector.Y * other.X;
Autodesk.DesignScript.Geometry.Vector v = Autodesk.DesignScript.Geometry.Vector.ByCoordinates(x, y, z);
return v;
}
/// <summary>
/// Obtains the cross product of two vectors.
/// </summary>
/// <param name="u">Vector3.</param>
/// <param name="v">Vector3.</param>
/// <returns>Vector3.</returns>
public static XYZ CrossProduct(this XYZ u, XYZ v)
{
double a = u.Y * v.Z - u.Z * v.Y;
double b = u.Z * v.X - u.X * v.Z;
double c = u.X * v.Y - u.Y * v.X;
return new XYZ(a, b, c);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment