How to check if a point(lonc,latc) lie on a great circle running from (lona,lata) to (lonb,latb) [closed] - latitude-longitude

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 11 years ago.
Improve this question
I'm trying to produce a boolean method that will return true if a point (lonc,latc) lies on a great circle arc starting at (lona,lata) and ending at (lonb,latb)
the point of the method returning true is so if you are in a location where you should be able to see this great circel the section you can see will be shown.
the jist is that you are at (lond,latd) with a small circle at 10degrees radius and I want to work out if the great circle and small circle will intersect. There will be multiple great circles but only one small circle.
I feel the simplest approach is to check any of the longitude and latitudes on the circumference of the small circle lie on a great circle line
any help will be most appreciated

You have three latitude-longitude pairs (θa, φa), (θb, φb) and (θc, φc) and you want to determine whether point (θc, φc) lies on the great circle determined by (θa, φa) and (θb, φb). You can accomplish this for example using the following calculations:
Convert all latitude-longitude pairs to (x, y, z) triples using the following formulae: x = sin(θ)*cos(φ), y = sin(θ)*sin(φ), z = cos(θ). This will give you three triples (xa, ya, za), (xb, yb, zb), (xc, yc, zc).
Determine the formula in cartesian coordinates of the plane going through points (xa, ya, za), (xb, yb, zb) and the origin (0, 0, 0). The formula is x+b*y+c*z=0 and we seek b and c which can be determined from two simultaneous equations obtained by substituting coordinates of points A and B for x, y and z in the plane formula x+b*y+c*z=0.
Calculate the distance between point (xc, yc, zc) and the plane determined in point 2 using the following formula: d=abs(xc+b*yc+c*zc)/sqrt(1+b*b+c*c).
From the distance in cartesian coordinates you can find the angular distance between the point (xc, yc, zc) and the great circle determined by (θa, φa) and (θb, φb) using the following formula: α = asin(d).
Since you should not compare floating point numbers exactly you should have an angular threshold which determines how far a point can be from the great circle for you to still consider the point to lie on the circle. You then compare α determined in point 4 with the threshold to come up with the boolean value you seek.

assuming you're working on a sphere wich has points a and b marking a cirlce arc. and the you have point c on this sphree and you want to check if c is on the circlearc between a and b...
for this you can check the following:
generate a plane wich is formed from the vectors center-to-a and center-to-b
check if point c intersects with this plane (assuming the point is actually on the sphere, and not above or below it's surface)

Related

How to find a point on a b-spline that is on the normal plane of a point on another b-spline using goemdl / nurbs

So the first problem will be explaining what I am after clearly.
I have two non-rational 3D b-splines. The first b-spline it the guiding spline. The second b-spline is a reference and it is essentially 'inside' of the first spline. ( the splines were generated in Solidworks )
Imagine a circular playground slide. The first spline is the center line of the slide. The second spline is the inside edge of the slide.
The inside spline will tend to be shorter than the center spline. The inside will also tend to have more curvature at any given point than the center.
The path of the slide is not perfectly circular. But the inside spline is always 'parallel' to the outside. ( very liberal use of the word parallel here )
What I am after:
Given a point along the center curve, I would like to find the point on the inside curve that is on the plane that is defined by the normal to the tangent of the center spline at that point.
Where I am at:
I am using the geomdl library in python to manipulate the splines.
I can choose a distance along the center spline and from geomdl I get the 3D point and the tangent vector (A,B,C) of that point and therefore the plane at that point that is normal to the spline at that point.
What I am doing:
From the tangent vector and the point I compute the equation of the plane in the form of:
Ax + By + Cz = D.
From there I guess at the point at the same distance on the inside spline and plug it into the equation for the plane that I already have. I use the error in D to guess at which way I should bump my guess on where the point on the inside curve might really be.
[ I understand that over the entire length of the two splines there may be more than one solution. i.e. if the curve wraps more than 180° there would be more than one point on the inside curve that lands on the plane defined by the center curve. In the local area that i am interested in this will not be a problem. Any second point would also be a long ways away from the center line. i.e. the correct point will be no more than 25 mm from the center point. A non-local point will be at least 3000 mm away. ]
This mostly works. But from time to time it fails. i.e. if D is very near 0 my guesses will diverge from the answer.
Currently I make 10 guesses, each guess having a smaller delta guess than the last.
I have a great number of these points to evaluate. My solution requires 10 X the number of calculations so it is not terribly efficient.
From my Google searches I believe that using the error in D in the equation of a plane may not be correct. I 'think' that D is the distance of the plane to the origin.(yes /no?) Therefore I am really comparing the distance of the two planes from the origin and not really from each other. If my guess happens to be on the "other side" of the origin then the distance's may be the same but opposite.
My Question:
What is the correct way to go about this?
Is my assumption that D is the distance from the plane to the origin?
Is driving the error in D between the two points valid?
What is the correct way to do this?
Restate my question in different terms
Given a plane (Ax + By + Cz = D) how do I find the point on a given b-spline that pierces ( or is coincident to ) that plane (using geomdl.bcurve)?
( I am very much in over my head here so please forgive if this does not make sense )

Need intersect point for a line coming from center of circle? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I have a line with start point as P1(x1, y1) & end Point as P2(x2, y2). This line is from the center of circle. The circle radius is r. Need a simple equation to identify the circle line intersect point?
Assuming P1 is the center of the circle, first get the slope of the line, then follow it from P1 to distance r along that direction.
phi = atan2(y2-y1, x2-x1)
x = x1 + r * cos(phi)
y = y1 + r * sin(phi)
The equation for a circle is (x-h)^2 - (y-k)^2 = r^2, where the center is (h, k) (which will end up being (0, 0) relative to your line)
Given two points, you can find the slope of the line, now you can plug it into the formula y = m*x + b.
You now have a system of two equations, solve for x or y in one equation, then plug that expression into the other equation and you will find the numeric value of the variable you did not solve for. You can then plug that back into the equation for a line and find the second variable.
Here is the general formula: http://mathworld.wolfram.com/Circle-LineIntersection.html
And some other answers: Circle line-segment collision detection algorithm?

How to find the point of collision between an irregular shape (built out of 3 circles) and a line

I'm making a program in which many weird shapes are drawn onto a canvas. Right now i'm trying to implement the last, and possebly hardest, one.
In this particular shape i need a way to find the location (on a 2d canvas) where the line hits the shape. The following image is an example of what i have right now.
The black dots are the points that a known to me (i also have the location of the center of the three open circles and the radius of these circles). Each of the three outer lines needs a line towards the center dot, ending at the point that it hits the circle. This shape can be turned 90, 180 or 270 degrees.
The shape should look something like the following:
If you need any other information, please ask me in the comments. I'm not very good at math so please be gentle, thanks!
If A and B are points forming a line, then you can describe any point on that line using coordinates:
x = t·Ax + (1−t)·Bx
y = t·Ay + (1−t)·By
0 ≤ t ≤ 1
You can also describe the circle with center M and radius r as
(x − Mx)2 + (y − My)2 = r2
So take the x and y from the equations of the line, and plug them into the equation of the circle. You obtain a quadratic equation in t. Its two solutions describe the two points of intersection between the line and circle. In your example, only one of them lies on the line segment, i.e. satisfies 0 ≤ t ≤ 1. The other describes a point on the extension of the segment past its endpoint. Take the correct value for t back to the equations of the line, and you obtain the x and y coordinates of the point of intersection.
If you don't know up front which circle you want to intersect with a given line, then intersect all three and choose the most appropriate point afterwards. Probably that is the point closest to the outside starting point of the line segment. The same goes in cases where both points of intersection lie on the segment.

Most efficient way to check if a point is in or on a convex quad polygon

I'm trying to figure out the most efficient/fast way to add a large number of convex quads (four given x,y points) into an array/list and then to check against those quads if a point is within or on the border of those quads.
I originally tried using ray casting but thought that it was a little overkill since I know that all my polygons will be quads and that they are also all convex.
currently, I am splitting each quad into two triangles that share an edge and then checking if the point is on or in each of those two triangles using their areas.
for example
Triangle ABC and test point P.
if (areaPAB + areaPAC + areaPBC == areaABC) { return true; }
This seems like it may run a little slow since I need to calculate the area of 4 different triangles to run the check and if the first triangle of the quad returns false, I have to get 4 more areas. (I include a bit of an epsilon in the check to make up for floating point errors)
I'm hoping that there is an even faster way that might involve a single check of a point against a quad rather than splitting it into two triangles.
I've attempted to reduce the number of checks by putting the polygon's into an array[,]. When adding a polygon, it checks the minimum and maximum x and y values and then using those, places the same poly into the proper array positions. When checking a point against the available polygons, it retrieves the proper list from the array of lists.
I've been searching through similar questions and I think what I'm using now may be the fastest way to figure out if a point is in a triangle, but I'm hoping that there's a better method to test against a quad that is always convex. Every polygon test I've looked up seems to be testing against a polygon that has many sides or is an irregular shape.
Thanks for taking the time to read my long winded question to what's prolly a simple problem.
I believe that fastest methods are:
1: Find mutual orientation of all vector pairs (DirectedEdge-CheckedPoint) through cross product signs. If all four signs are the same, then point is inside
Addition: for every edge
EV[i] = V[i+1] - V[i], where V[] - vertices in order
PV[i] = P - V[i]
Cross[i] = CrossProduct(EV[i], PV[i]) = EV[i].X * PV[i].Y - EV[i].Y * PV[i].X
Cross[i] value is positive, if point P lies in left semi-plane relatively to i-th edge (V[i] - V[i+1]), and negative otherwise. If all the Cross[] values are positive, then point p is inside the quad, vertices are in counter-clockwise order. f all the Cross[] values are negative, then point p is inside the quad, vertices are in clockwise order. If values have different signs, then point is outside the quad.
If quad set is the same for many point queries, then dmuir suggests to precalculate uniform line equation for every edge. Uniform line equation is a * x + b * y + c = 0. (a, b) is normal vector to edge. This equation has important property: sign of expression
(a * P.x + b * Y + c) determines semi-plane, where point P lies (as for crossproducts)
2: Split quad to 2 triangles and use vector method for each: express CheckedPoint vector in terms of basis vectors.
P = a*V1+b*V2
point is inside when a,b>=0 and their sum <=1
Both methods require about 10-15 additions, 6-10 multiplications and 2-7 comparisons (I don't consider floating point error compensation)
If you could afford to store, with each quad, the equation of each of its edges then you could save a little time over MBo's answer.
For example if you have an inward pointing normal vector N for each edge of the quad, and a constant d (which is N.p for one of the vertcies p on the edge) then a point x is in the quad if and only if N.x >= d for each edge. So thats 2 multiplications, one addition and one comparison per edge, and you'll need to perform up to 4 tests per point.This technique works for any convex polygon.

formulas in Projectile Motion?

how can i calculate angle to reach particular height?
suppose i want height 320.time is increasing as 0.1.
i am using h = (u sin(angle))^2 / 2g;
where can i put the time?
The inverse of the sin() function is called the arcsine, or sin-1 in mathematical notation. In many programming languages, it's available as asin().
From my answer to your previous question:
Where y is the height you want to reach (320 in this case), and assuming you're starting at y=0:
angle = arctan( 2*y / x )
where x is the distance on the X-AXIS between your starting point and the point where you want to reach that height, which is necessary in order to specify an angle.
If you really want me to, I can derive this one for you, but it follows directly from my answer to your previous question.
Also (since I can't comment answers yet I'm saying this here), you may be having issues getting an angle "less than 1" because you're trying to use degrees instead of radians. Many math libraries work in radians, so convert your angles.