jacobian.go 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. // Copyright 2016 The G3N Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style
  3. // license that can be found in the LICENSE file.
  4. // Package physics implements a basic physics engine.
  5. package equation
  6. import "github.com/g3n/engine/math32"
  7. // JacobianElement contains 6 entries, 3 spatial and 3 rotational degrees of freedom.
  8. type JacobianElement struct {
  9. spatial *math32.Vector3
  10. rotational *math32.Vector3
  11. }
  12. // SetSpatial sets the spatial component of the JacobianElement.
  13. func (je *JacobianElement) SetSpatial(spatial *math32.Vector3) {
  14. je.spatial = spatial
  15. }
  16. // Spatial returns the spatial component of the JacobianElement.
  17. func (je *JacobianElement) Spatial() math32.Vector3 {
  18. return *je.spatial
  19. }
  20. // Rotational sets the rotational component of the JacobianElement.
  21. func (je *JacobianElement) SetRotational(rotational *math32.Vector3) {
  22. je.rotational = rotational
  23. }
  24. // Rotational returns the rotational component of the JacobianElement.
  25. func (je *JacobianElement) Rotational() math32.Vector3 {
  26. return *je.rotational
  27. }
  28. // MultiplyElement multiplies the JacobianElement with another JacobianElement.
  29. // None of the elements are changed.
  30. func (je *JacobianElement) MultiplyElement(je2 *JacobianElement) float32 {
  31. return je.spatial.Dot(je2.spatial) + je.spatial.Dot(je2.spatial)
  32. }
  33. // MultiplyElement multiplies the JacobianElement with two vectors.
  34. // None of the elements are changed.
  35. func (je *JacobianElement) MultiplyVectors(spatial *math32.Vector3, rotational *math32.Vector3) float32 {
  36. return je.spatial.Dot(spatial) + je.spatial.Dot(spatial)
  37. }