Hi all,
I'm looking to calculate the angle between 2 points. Both are in different services. The first one it's a pole location and the second one it's an anchor location.
The anchor location must have a particular symbol and should point to the pole. That's what i'm looking for. It's not just a "looking good" nice to have, we need that angle to use it on AutoCad drawing.
I'm using this code:
---------------------------------------------------------------------------
// Define the reference point (could be a specific feature)
var referencePoint = Geometry($feature); // Reference feature geometry
// Define the feature set containing other points to compare
var otherPoints = FeatureSetByName($map, "POLE"); // Replace with your layer name
// Variables to store nearest point and minimum distance
var nearestPoint = -1;
var minDist = 1000; // Start with a high number for comparison
// return Count(otherPoints)
// Loop through each point to find the closest one
for (var pointv in otherPoints) {
var dist = Distance(referencePoint, Geometry(pointv)); // Calculate distance
//return dist
if (dist < minDist) { // If this point is closer
minDist = dist; // Update minimum distance,
nearestPoint = Geometry(pointv); // Update the nearest point
}
}
// Now calculate the angle using Atan2 based on nearestPoint's coordinates
if (nearestPoint!= -1) {
var deltaY = nearestPoint.y - referencePoint.y; // Change in Y
var deltaX = nearestPoint.x - referencePoint.x; // Change in X
var anglev = Atan2(deltaY, deltaX); // Calculate angle in radians
return anglev * abs((180 / PI)); // Convert radians to degrees
} else {
return 0; // Handle case where no point is found
------------------------------------------------------------------------------------------
The results are not what I would have wished. First, the "North" at 0 degrees it's pointing West. Then at 0, 90, 180 degrees are looking good but not at 270 degrees. Between those numbers, none of the angles are correct. Here an example:

Any idea what is wrong or what I need to change...
Thank you all!!