let me begin by saying that I've read through Calculate point A from given point E and angle and afterwards calculate Point A from E and angle , Calculate point, given x, y, angle, and distance , a problem involving trigonometry functions, and especially How to get coordinates of a point in a coordinate system based on angle and distance and none of them managed to lift the veil of confusion, surrounding me.
What I am doing: I want to create a sort of Instantaneous Field of View (FOV) for a bunch of sequences of points; the FOVs would represent what is visible from each point, depending of course, on the direction at which we are looking at ( 0 - North; 90 - East; 180 - South; 270 - West; 360 - North). The FOV is essentially a triangle, where the central (C) vertex is the point itself, vertex A and vertex B, whose coordinates I am looking for, being the ones connected to the base of the triangle.
The code snippet: I am essentially approaching this via leveraging two right triangles, that together constitute the FOV, like so:
--------- A VERTEX -------------
for (p in 1:nrow(pnp.90.deg@data)){ #pnp is the spatial points dataframe, containing attribute information such as lon/lat(coordinates) and ca(camera angle - showing the direction of sight/movement in degrees)
a_alfa1 <- pnp.90.deg@data$ca - (pnp.90.deg@data$ca - 60)
a_alfa1rad <- a_alfa1 * (pi/180)
a_x1 <- pnp.90.deg@data$lon + 0.00035 * cos(a_alfa1rad)
a_y1 <- pnp.90.deg@data$lat + 0.00035 * sin(a_alfa1rad)
avert1 <- cbind(a_x1, a_y1)
colnames(avert1) <- c("lon", "lat")
avert.90<-SpatialPoints(avert1, proj4string=CRS("+proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0"), bbox=NULL)
}
--------- B VERTEX -------------
for (p in 1:nrow(pnp.90.deg@data)){
b_alfa1 <- pnp.90.deg@data$ca - (pnp.90.deg@data$ca + 60)
b_alfa1rad <- b_alfa1 * (pi/180)
b_x1 <- pnp.90.deg@data$lon + 0.00035 * cos(b_alfa1rad)
b_y1 <- pnp.90.deg@data$lat + 0.00035 * sin(b_alfa1rad)
bvert1 <- cbind(b_x1, b_y1)
colnames(bvert1) <- c("lon", "lat")
bvert.90<-SpatialPoints(bvert1, proj4string=CRS("+proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0"), bbox=NULL)
}
The result: the code produces the triangle as one would expect, yet it does so only when the angle (ca) is between 0-90 degrees:
The Problem
This formula doesn't seem to work for other camera angles. To my mind (and according to the provided links to topics) the formula should be universally applicable for any angle measure. Can someone provide some input on whether I am a) using the right formula and b) using it in the correct way.
UPDATE: link to the spatial points data frame in shapefile format: https://drive.google.com/file/d/1ax5OG8c8Cl-Hz3N16ye9OoG4z7l8HSAQ/view?usp=sharing
UPDATE 2: The process of getting from the pnpover (the shared spdf) to pnp.90.deg is just a spatial subset:
pnp.90.deg <- subset(pnpover, pnpover@data$ca <= 90)
I decided to bucket looking angles in ranges of 0-90; 91-180; 181-270; 271-360 in order to test what was going wrong.
Thank you kindly!
alfa1
is always +- 60 and does not depend onpnp.90.deg@data$ca
. Is this correct? – Nico Schertler