josemorval

Point and derivates over sphere

Oct 31st, 2016
305
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.08 KB | None | 0 0
  1. Vector3 EvaluateOnSphere(float r, float theta, float psi, float offsetTheta, float offsetPsi){
  2.  
  3.     Vector3 v = new Vector3(
  4.         Mathf.Cos(2f*Mathf.PI*theta+offsetTheta)*Mathf.Sin(2f*Mathf.PI*psi+offsetPsi),
  5.         Mathf.Cos(2f*Mathf.PI*psi+offsetPsi),
  6.         Mathf.Sin(2f*Mathf.PI*theta+offsetTheta)*Mathf.Sin(2f*Mathf.PI*psi+offsetPsi)
  7.     );
  8.  
  9.     return r * v;
  10.  
  11. }  
  12.  
  13. Vector3 EvaluateDerivateSphere(float theta, float psi, float magTheta, float magPsi, float offsetTheta, float offsetPsi){
  14.  
  15.     Vector3 vtheta = new Vector3 (
  16.         -Mathf.Sin (2f * Mathf.PI * theta + offsetTheta) * Mathf.Sin (2f * Mathf.PI * psi + offsetPsi),
  17.         0f,
  18.         Mathf.Cos (2f * Mathf.PI * theta + offsetTheta) * Mathf.Sin (2f * Mathf.PI * psi + offsetPsi)
  19.         );
  20.  
  21.     vtheta.Normalize ();
  22.  
  23.     Vector3 vpsi = new Vector3 (
  24.         Mathf.Cos (2f * Mathf.PI * theta + offsetTheta) * Mathf.Cos (2f * Mathf.PI * psi + offsetPsi),
  25.         -Mathf.Sin (2f * Mathf.PI * psi + offsetPsi),
  26.         Mathf.Sin (2f * Mathf.PI * theta + offsetTheta) * Mathf.Cos (2f * Mathf.PI * psi + offsetPsi)
  27.     );
  28.  
  29.     vpsi.Normalize ();
  30.  
  31.     return magTheta * vtheta + magPsi * vpsi;
  32.  
  33. }
Advertisement
Add Comment
Please, Sign In to add comment