Assume you're given a circle with the line AB containing its center O, such that A and B are on the circle (OA=OB=radius). A tangent t is drawn on the point A, and
I should calculate the mapping of certain points (a,b,c,d...) of the circle to the points on the tangent (at, bt, ct, dt, ...) such that the distance Aa (the distance along the circle) is the same as the distance Aat (the distance along the tangent) (and the same for the distances Ab, Ac, Ad). But, here, certain constraint should be considered: those points of the circle (among (a, b, c, d)) that are from one side of the circle from A to B should be placed on one side of the tangent (the nearer), and those from the other side of the circle form A to B should be placed on the other side. Basically, the circle should be split at B, and then mapped to the tangent. I hope this explanation is sufficient enough.
It should be noted that I have information about coordinates of A, B, O, a, b, c, d. I supposed to calculate (at, bt, ct, dt).
For solving this problem, I have two approaches, but I'm not sure how I could make sure they always work correctly.
1) I calculate the equation of the tangent at point A. Then for each point (a, b, c, d) I calculate the distance from A (along the circle), and use these distances for calculating (at, bt, ct, dt...) along the tangent. What I dont know here is how to calculate the distances
from A to (a, b, c, d). The problem is the 'proper side' determination, meaning how should I determine whether the point should be mapped on one side of the tangent or the other. What would be the way to determine this.
2) I calculate the equation of the tangent at point A. Then for each point (a, b, c, d) I calculate the distance from A (along the circle), and use these distances for calculating (at, bt, ct, dt...) along the tangent. To determine the 'proper side' of a given point, I might use the projection of that point to the tangent. But, even with this, how I know 'which side is which'? Perhaps there are much simpler ways to do this.
Any suggestion on how to do this is welcome. In case I was not precise enough, I'll elaborate.
A better suggestion would be to calculate a coordinate transformation that would map the circle into a unit circle with the centre at the origin, so that A will have coordinates (1, 0) (and B respectively (-1, 0)).
The transformation should be dilation with rotation.
Now, the distance on Aa is just the angle aOA measured in radians. So you can easily calculate at, it is (1, atan2(y, x)) where (x, y) are the coordinates of a.
Now, the only thing you need is to return to the original coordinate system, applying the inverse transformation.
To determine which "side" of the circle you're on, you basically need to determine which side of the line AB you're on. For the answer to that, see e.g. Determine which side of a line a point lies.
Related
This question is a bit specific. Assume for simplicity that I have a unit circle, i.e. a circle centered on the origin (0,0) with radius 1. On this circle I have three points: A, B, and C. Assume that B and C are fixed, and that A can be moved along the circle's circumference.
Question: What conditions can I check efficiently to ensure that A is not moved outside the arc between B and C originally containing it?
As a point of clarification: I do not just wish to detect whether the point is on this arc or not (i.e., get a boolean), but to have a quantifiable measure (for example, of distance) so I can prevent it from being moved outside. You can imagine my setup like this, restricting point A to the red arc:
Here are some ideas I have pondered so far, but none were successful:
Limit the angle alpha of A = [cos(alpha),sin(alpha)] to the origin between the angles beta and gamma of B=[cos(beta),sin(beta)] and C=[cos(gamma),sin(gamma)], where alpha, beta, and gamma are angles in radians. Unfortunately, this naive case only works in scenario (a) above. If the arc to which A is restricted crosses the (in my case, western) discontinuity from +pi/-pi, a naive upper and lower bound won't do.
Calculate the length of the arcs between A-to-B and A-to-C, then ensure that as A is moved this sum does not change. Unfortunately, I have only found this solution to calculate the arcs between two points, and it always calculates the shorter arc. In scenario (c), however, the correct arc A-to-B is the larger one.
Given any two points on a circle, in your case B and C, there are of course two possible arcs. We use A to select between the two options. You say you want to prevent a point, say D, from moving outside this arc. I'm interpreting this to mean that we want a function which, if D lies on the arc defined by BC and A, returns D, otherwise it returns B or C, depending on which is nearer to D.
We can define the following function to implement this scheme:
def contstrainPoint(A, B, C, D)
M = midpoint(B, C)
If dot(MA, MD) >= 0
return D
else if(dot(MB, MD) >= 0
return B
else
return C
Where M is the midpoint of the chord BC and dot is the dot product function.
Take the cross product (A-B)x(A-C). This will have one non-zero component, normal to the plane. That component will vary smoothly, positive when A is on one arc, negative when it is on the other, and zero when it crosses B or C.
Given a point p exterior to an axially aligned, origin centered ellipse E, find the (upto) four unique normals to E passing through p.
This is not a Mathematica question. Direct computation is too slow; I am willing to sacrifice precision and accuracy for speed.
I have searched the web, but all I found involved overly complex calculations which if implemented directly appear to lack the performance I need. Is there a more "programmatical" way to do this, like using matrices or scaling the ellipse into a circle?
Let's assume the ellipse E is in "standard position", center at the origin and axes parallel to the coordinate axes:
(x/a)^2 + (y/b)^2 = 1 where a > b > 0
The boundary cases a=b are circles, where the normal lines are simply ones that pass through the center (origin) and are thus easy to find. So we omit discussion of these cases.
The slope of the tangent to the ellipse at any point (x,y) may be found by implicit differentiation:
dy/dx = -(b^2 x)/(a^2 y)
For the line passing through (x,y) and a specified point p = (u,v) not on the ellipse, that is normal to ellipse E when its slope is the negative reciprocal of dy/dx:
(y-v)/(x-u) * (-b^2 x)/(a^2 y) = -1 (N)
which simplifies to:
(x - (1+g)u) * (y + gv) = -g(1+g)uv where g = b^2/(a^2 - b^2)
In this form we recognize it is the equation for a right rectangular hyperbola. Depending on how many points of intersection there are between the ellipse and the hyperbola (2,3,4), we have that many normals to E passing through p.
By reflected symmetry, if p is assumed exterior to E, we may take p to be in the first quadrant:
(u/a)^2 + (v/b)^2 > 1 (exterior to E)
u,v > 0 (1'st quadrant)
We could have boundary cases where u=0 or v=0, i.e. point p lies on an axis of E, but these cases may be reduced to solving a quadratic, because two normals are the (coinciding) lines through the endpoints of that axis. We defer further discussion of these special cases for the moment.
Here's an illustration with a=u=5,b=v=3 in which only one branch of the hyperbola intersects E, and there will be only two normals:
If the system of two equations in two unknowns (x,y) is reduced to one equation in one unknown, the simplest root-finding method to code is a bisection method, but knowing something about the possible locations of roots/intersections will expedite our search. The intersection in the first quadrant is the nearest point of E to p, and likewise the intersection in the third quadrant is the farthest point of E from p. If the point p were a good bit closer to the upper endpoint of the minor axis, the branches of the hyperbola would shift together enough to create up to two more points of intersection in the fourth quadrant.
One approach would be to parameterize E by points of intersection with the x-axis. The lines from p normal to the ellipse must intersect the major axis which is a finite interval [-a,+a]. We can test both the upper and lower points of intersection q=(x,y) of a line passing through p=(u,v) and (z,0) as z sweeps from -a to +a, looking for places where the ellipse and hyperbola intersect.
In more detail:
1. Find the upper and lower points `q` of intersection of E with the
line through `p` and `(z,0)` (amounts to solving a quadratic)
3. Check the sign of a^2 y(x-u) - b^2 x(y-v) at `q=(x,y)`, because it
is zero if and only `q` is a point of normal intersection
Once a subinterval is detected (either for upper or lower portion) where the sign changes, it can be refined to get the desired accuracy. If only modest accuracy is needed, there may be no need to use faster root finding methods, but even if they are needed, having a short subinterval that isolates a root (or root pair in the fourth quadrant) will be useful.
** more to come comparing convergence of various methods **
I had to solve a problem similar to this, for GPS initialization. The question is: what is the latitude of a point interior to the Earth, especially near the center, and is it single-valued? There are lots of methods for converting ECEF cartesian coordinates to geodetic latitude, longitude and altitude (look up "ECEF to Geodetic"). We use a fast one with only one divide and sqrt per iteration, instead of several trig evaluations like most methods, but since I can't find it in the wild, I can't give it to you here. I would start with Lin and Wang's method, since it only uses divisions in its iterations. Here is a plot of the ellipsoid surface normals to points within 100 km of Earth's center (North is up in the diagram, which is really ECEF Z, not Y):
The star-shaped "caustic" in the figure center traces the center of curvature of the WGS-84 ellipsoid as latitude is varied from pole to equator. Note that the center of curvature at the poles is on the opposite side of the equator, due to polar flattening, and that the center of curvature at the equator is nearer to the surface than the axis of rotation.
Wherever lines cross, there is more than one latitude for that cartesian position. The green circle shows where our algorithm was struggling. If you consider that I cut off these normal vectors where they reach the axis, you would have even more normals for a given position for the problem considered in this SO thread. You would have 4 latitudes / normals inside the caustic, and 2 outside.
The problem can be expressed as the solution of a cubic equation which
gives 1, 2, or 3 real roots. For the derivation and closed form
solution see Appendix B of Geodesics on an ellipsoid of revolution. The boundary between 1 and 3 solutions is an astroid.
Knowing the vertices of a 3D triangle, and the x, y coordinates of the projection on the horizontal plane of a point E belonging to the triangle. Also the angle alpha is given, representing the angle respect to the edge AB of a segment that lies on the same plane of the triangle. I would like to find out 3 things:
for a given alpha, on which side is F
what is the angle created by the "exit" side with the segment EF (considering always the following vertex in a clockwise way)
the length of EF
The length of the segment BF if BC is the exit side (clockwise again)
This is though... and I want to see how it will perform.
Thank you.
grid http://www.keplero.com/upps/mesh.jpg
Find point E. Draw a line perpendicular to the horizontal plane, passing through E's projection. Point E is the intersection of that line and the plane the triangle lies on. (if the triangle's plane is perpendicular to the horizontal plane, you don't have enough information to find E.)
Perform a transformation on points A, B, C, E so that they lie on the horizontal plane. Use only rotations and translations so the angles and distances are preserved. With this step, the problem can be solved in only two dimensions, which simplifies things.
Draw a ray extending out from E, that has angle alpha with respect to AB.
For each of AB, BC, CA, determine whether the ray extending from E intersects it. Point F is the intersection of the ray and whichever line segment it intersects. (If the ray passes through a vertex of the triangle rather than an edge, then you may not be able to get meaningful answers your questions involving the "exit" side.)
Using the position of F, determine the answers of each of your bullet points.
Optionally, perform the reverse of the transformation done in step 2, to get the true position of F.
I am trying to find all the points with integer coordinates that lie inside of a tetrahedron (I want to somehow be able to loop through them). I know the coordinates of the four points (A, B, C, D) that define the tetrahedron.
What I'm currently doing is I find the bounding box of the tetrahedron (minimum and maximum x, y, z coordinates of A, B, C, D) and then do a loop through all of the points inside the bounding box. For every such point, I calculate the barycentric coordinates (using the equations from Wikipedia) and check if the point is inside the tetrahedron (if any of the barycentric coordinates is negative or bigger than 1, the point isn't inside).
Is there a better way to do this? Currently there is around 1/6 chance that the point I am testing (from the bounding box) really lies inside the tetrahedron, so I think I'm doing too many unnecessary computations.
I am working with a list of tetrahedra that I generated by triangulating a bigger volume (I am expanding the volume and want to interpolate the missing values using tetrahedral interpolation). I am not using any external libraries.
Another idea for improving:
check if a "rod" parrallel to z-axis (i.e. x=4, y=6) runs through the tetrahedron. If not, no values with (x=4, y=5, z) can be inside.
Else, find where the rod intersects the edge of the tetrahedron (by finding out where the planes that make up the edge of the tetrahedron intersect it).
Say these planes intersect at z=1.3 and z= 10.04. Then you know all points (4,5, 2) to (4,5,10) are inside.
Repeat for all values of x and y.
This should be faster in practice, because it will save you 1 loop.
Your approach is the correct one. There are some possible optimisations, which might be worth it or not depending on the requirements. For example:
There is an easier way to check if a given point is inside or outside of the tetrahedron.
It amounts to checking the which half-space the point belongs to with respect to each of the 4 sides of the tetrahedron:
Each side is defined by 3 points (say A, B, C). Then a plane normal is a (C-A)x(B-A) (that's cross product of vectors in the plane). If this coordinates are (a,b,c), then the plane equation is F(x,y,z) = ax+by+cz = 0. For a given point (x0, y0, z0) the sign of F(x0,y0,z0) determines which half-plane the points belong to.
The point is that you can precompute plane quations for each side of the tetrahedron as well as the sign which corresponds to 'outside' an then the check for a given point amounts to doing at most 4 evaluations (one for each side), each taking 3 multiplications and 2 additions.
I am trying to find circumcenter of Given Three point of Triangle……..
NOTE: all these three points are with X,Y and Z Co-Ordinate Means points are in 3D
I know that the circumcenter is the point where the right bisectors intersect….
But for that I have to find middle point of each side then the right bisectors and then intersection point of that …..this is long and error some process……
Is there not any formula which just takes as input these three points of triangle and giving us the Circumcenter of Triangle ……?
Thanks………
The wiki page on Circumscribed circle has it in terms of dot and cross products of the three vertex vectors. It also has a formula for the radius of the circle, if you are so interested.
First of all, you need to make sure that points are not collinear. i.e. do not lie in the same line. For that you need to find the direction cosines of the lines made by three points, and if they have same direction cosines, halt, you can't get circle out of it.
For direction cosine please check this article on wikipedia.
(A way of finding coordinate-geometry and geometry -- based on the theorem that, a perpendicular line from center of circle bisects a chord)
Find the equation of the plane.
This equation must reduce to the form
and the direction cosines (of the line perpendicular to plane determines the plane), so direction cosines of the line perpendicular to this line is
given by this link equations -- 8,9,10 (except replace it for l, m, n).
Find the equation of the lines (all three) in 3-d
(x-x1)/l=(y-y1)/m=(z-z1)/n (in terms of direction cosines) or
(x-x1)/(x2-x1)=(y-y1)/(y2-y1)=(z-z1)/(z2-z1)
Now we need to find the equation of line
a) this perpendicular to the line, from 2 (let l1, m1, n1 be direction cosines of this line)
b) must be contained in place from 1 (let l2, m2, n2 be direction cosines of this line perpendicular to plane)
Find and solve (at least two lines) from 3, sure you will be able to find the center of the circle.
How to find out equation ??? as we are finding the circum-center, we will get our points (i.e. it is the midpoint of the two points) and for a) we have
l1*l+m1*m+n1*n = 0 and l2*l+m2*m+n2*n = 0 where l, m, n are direction cosines of our, line, now solving this two equation, we can get l, m interms of n. And we use this found out (x1,y1,z1) and the value of l, m, 1 and we will have out equation.
The other process is to solve the equation given in this equation
https://stackoverflow.com/questions/5725871/solving-the-multiple-math-equations
Which is the deadliest way.
The other method is using the advantage of computer(by iteration) - as I call it (but for this you need to know the range of the coordinates and it consumes lot of memory)
it's like this (You can make it more precise by incrementing at 1/10) but certainly bad way.
for(i=minXrange, i>=maxXrange; i++){
for(j=minYrange, j>=maxYrange; j++){
for(i=minZrange, i>=maxZrange; k++){
if(((x1-i)^2 + (y1-j)^2 + (z1-k)^2) == (x2-i)^2 + (y2-j)^2 + (z2-k)^2) == for z)){
return [i, j, k];
}
}
}
}