Cross product fuction in swift ios

1.4k views Asked by At

In which swift library i will get cross product funtion

like cross(normalize(vector1),normalize(vector2))

i want angle direction between three scnnode joint with line

let node0 :SCNNode = self.nodes[1]
let node1 :SCNNode = self.nodes[2]
let node2 :SCNNode = self.nodes[3]
let vector1 = float3((node0.position.x - node1.position.x), (node0.position.y - node1.position.y), (node0.position.z - node1.position.z))
let vector2 = float3((node2.position.x - node1.position.x), (node2.position.y - node1.position.y), (node2.position.z - node1.position.z))
let dotProduct = dot(normalize(vector1), normalize(vector2))
let theta = acos(dotProduct)

This is my sample code and theta is and radian angle between those point and is perfect but how to get angle direction is my question

1

There are 1 answers

1
Rohan Pawar On

You can import simd library so that you will get cross product function

import simd
let crossp = cross(normalize(vector1), normalize(vector2))
let dotpOfcross  = dot(crossp,float3.init(node0.position))

I think this is what you want as per your question please check and let here know.