'Angle between two non intersecting lines
Consider there are two lines, l1, l2 and they might be intersecting or non-intersecting. Is there any elegent way to find a angle between them? Thank you
import numpy as np
from shapely import LineString
l1 = [(0,0), (1,1)]
l2 = [(0.5, 1), (0.5, 2)]
ls1 = LineString(l1)
ls2 = LineString(l2)
angle = compute_angle(ls1, ls2)
# This is I want to avoid because I have very big dataset and performance will degrade
def compute_anlge(l1, l2):
#Extend line1 and line2 in both direction util they intersect
# Find intersection point
# Create new lines with the intersection point
# find angle and return
Solution 1:[1]
First, find the angle for each segment by moving it to the origin:
seg = np.array(l2)
seg = seg[1] - seg[0]
Then, use np.angle
angle_l2 = np.angle(complex(*(seg)), deg=True)
Then, you can simply calculate the difference between the angles.
Solution 2:[2]
Using the slopes of two lines, you can just get the arc tangents to find their respective angles with respect to origin. Then, get the positive difference of two angles. All done!
import math
from math import pi as PI
l1 = [(0,0), (1,1)]
l2 = [(0.5, 1), (0.5, 2)]
m1 = (l1[1][1]-l1[0][1])/(l1[1][0]-l1[0][0])
m2 = (l2[1][1]-l2[0][1])/(l2[1][0]-l2[0][0])
angle_rad = abs(math.atan(m1) - math.atan(m2))
angle_deg = angle_rad*180/PI
There, with both radian and degree values.
Solution 3:[3]
I am not sure about this either as I am having this problem too. But, I am logging (via print_r) the call to $this->request->getFileMultiple('my_file_name_here') and noticed when I submitted my form without having a file attached, a file object was created (hence returning TRUE - I think). The object has all the properties empty, except the error property is set to 4 and if this maps to PHP's File Upload Errors, it means no file was uploaded.
I wonder if the object is created specifically because of this error?
Here is the code from my logging when I submit the form with no file attached.
(
[0] => CodeIgniter\HTTP\Files\UploadedFile Object
(
[path:protected] =>
[originalName:protected] =>
[name:protected] =>
[originalMimeType:protected] =>
[error:protected] => 4
[hasMoved:protected] =>
[size:protected] => 0
[pathName:SplFileInfo:private] =>
[fileName:SplFileInfo:private] =>
)
)
I honestly don't know how to (or not to) check for an if($this->request->getFileMultiple('my_file_name_here')) if it is going to always be true whether a file is attached or not.
I could be totally wrong in all this. I am up for any help and suggestions.
If this is totally wrong or not in accord with the site rules, take it down by all means.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | |
| Solution 2 | Seraph Wedd |
| Solution 3 |
