You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
let dot_product = vector_a.normalize_or_zero().dot(vector_b.normalize_or_zero());
802
+
let angle = dot_product.acos();
803
+
if radians { angle }else{ angle.to_degrees()}
804
+
}
805
+
806
+
pubtraitToPosition{
807
+
fnto_position(self) -> DVec2;
808
+
}
809
+
implToPositionforDVec2{
810
+
fnto_position(self) -> DVec2{
811
+
self
812
+
}
813
+
}
814
+
implToPositionforDAffine2{
815
+
fnto_position(self) -> DVec2{
816
+
self.translation
817
+
}
818
+
}
819
+
820
+
/// Calculates the angle needed for a rightward-facing object placed at the observer position to turn so it points toward the target position.
821
+
#[node_macro::node(category("Math: Vector"))]
822
+
fnangle_to<T:ToPosition,U:ToPosition>(
823
+
_:implCtx,
824
+
/// The position from which the angle is measured.
825
+
#[implementations(DVec2,DAffine2,DVec2,DAffine2)]
826
+
observer:T,
827
+
/// The position toward which the angle is measured.
828
+
#[expose]
829
+
#[implementations(DVec2,DVec2,DAffine2,DAffine2)]
830
+
target:U,
831
+
/// Whether the resulting angle should be given in as radians instead of degrees.
832
+
radians:bool,
833
+
) -> f64{
834
+
let from = observer.to_position();
835
+
let to = target.to_position();
836
+
let delta = to - from;
837
+
let angle = delta.y.atan2(delta.x);
838
+
if radians { angle }else{ angle.to_degrees()}
839
+
}
840
+
783
841
// TODO: Rename to "Magnitude"
784
842
/// The magnitude operator (`‖x‖`) calculates the length of a vec2, which is the distance from the base to the tip of the arrow represented by the vector.
0 commit comments