I'd like to scale GPS coordinate by given direction and length.
E.g. I have two points A,B. I know their GPS position (also in cartesian format) and I'd like to change the length of line AB by 1.5 where point A should be intact and B should move to new position B'
any ideas?
I am not sure if I understand your question. Do you want to compute a location which is on the line between two known points A and B but half the distance between A and B behind B on that line?
Compute the vector difference between A and B: if A has coordinates latA, lonA, and B has coordinates latB, lonB than the difference L = B-A has coordinates latL = latB-latA and lonL = lonB-lonA.
The point you are looking for than has coordinates latA + 1.5 * latL, and lonA + 1.5 * lonL.
This uses the representation of the line passing through A and B as X = A + l * (B-A); all the points X satisfying the vector equation are on the line.
Of course this assumes a Cartesian coordinate system. However, for short distances the result should be ok.
Related
my math is a bit rusty seeing as how it's been years.
I added a small example graph to make this more clear.
I have 2 points in a cartesian coordinate system. On this line I take a random point, in this example the center. Now I draw the perpendicular line on that point. I want to know the coordinate of a point on that line, a certain known distance from that point. What's the formula to calculate this?
Graph: http://i44.tinypic.com/9vcjlf.png
In short
Known constants:
the coordinates of points A, B and C.
the lengths t1, t2, t3
Required:
the coordinate of the colored points
Thanks in advance
If these are the coordinates of A, B:
A = (Ax, Ay)
B = (Bx, By)
Then the vector from A to B is given by:
vector AB = (Bx-Ax, By-Ay) = (BAx, BAy)
And the unit vector (the vector of length 1) which points in the same direction is given by:
(BAx, BAy)
unit vector AB = ------------------, where length = sqrt(BAx^2 + BAy^2)
length
Now, the unit vector which is perpendicular to AB is given by:
(-BAy, BAx)
unit vector perpendicular to AB = -------------
length
There are two possible unit vectors perpendicular to AB. The one shown above is what you'd obtain by
rotating the unit vector AB counterclockwise by 90 degrees.
Given the above calculations, here are the desired coordinates:
coordinate at t1 = (Bx, By) + t1 * (unit vector perpendicular to AB)
coordinate at t2 = (Bx, By) + t2 * (unit vector perpendicular to AB)
coordinate at t3 = (Bx, By) - t3 * (unit vector perpendicular to AB)
To be explicit,
(Bx + t1*(-By+Ay), By + t1*(Bx-Ax))
coordinate at t1 = -------------------------------------
sqrt((Bx-Ax)^2 + (By-Ay)^2)
The others formulas are very similar.
I have:
axis-aligned rectangle R;
non-vertical line A (specified by two points);
vertical line B (specified by x-coordinate).
All objects above is specified by integer coordinates.
I need to check, if result of crossing A and B is in the R. But I can't just calculate result of crossing A and B because it may be unpresentable in integer coordinates. Also I can't convert it to doubles because I need to get absolutely accurate result without any inaccuracy.
So, how can I check it?
If lines are specified by integer coordinates, then their crossing point has rational coordinates, which may be compared with absolutely precision.
Let's A goes through points (ax0, ay0) and (ax1, ay1), and B is at X0 coordinate.
Then crossing point Y-coordinate is (ay0*(ax1-ax0)+(X0-ax0)*(ay1-ay0))/(ax1-ax0) = p/q, where p and q are integer, and q is positive (negate nominator if needed).
Then p may be compared with R.Top*q and R.Bottom*q
[let's ignore not interesting case when B does not intersect R]
R cuts a segment from B, let's call it S. Intersection of B and A lies inside of R if and only if A crosses S.
Finding points of S is trivial.
To check whether a line crosses a segment, you should check that ends of S lie on different sides from A - this can be checked by signed angles.
Let's say that the 2 points on A are (x0, y0) and (x1, y1), with 'x0 < x1'.
The rectangle is determined by a x-coordinate xR and a y-coordinate yR
The B line is determined by the x-coordinate xB
The point you're looking for is (xB, yB), where yB is to be determined somehow, by manipulating integers only :
So first, you need to check
if xB * xR >= 0 (same side of the x-coordinate)
if abs(xB) <= abs(xR) (the B line cuts the rectangle)
If it's ok, then you need to check that this integer (which is equal to (x1-x0)yB)
Y = (y1-y0)(xB-x0)+(x1-x0)y0
verifies
Y * yR >=0 (same side of the y-coord)
abs(Y) <= (x1-x0) * abs(yR) (meaning that your intersection point is in the R area regarding its y-coord)
Your point is inside R if and only if the 4 conditions are true.
Hope it helps.
I have an image that represents a projection. I am going to explain the problem with an example:
In the screen, there is a line from one point E(100,200) to another point
H (150,100). A represent one point
that in the real world is at 200 cm of
distance while B is a point that in
real world is at 300 cm of distance.
The thing that I would like to know is this:
Given one point of the line that passes for these two points, is there a way to calculate the z distance data that it should have?
What if the z distance is not a linear function but is some logarithmic function?
If it's not clear ask me everything,
Cheers
I think what you're getting at is perspective correct interpolation. If you know the depth at E and a depth at H, and B is on the line (in the image) joining these two points, solve for the depth at B with:
1/Zb = s * 1/Ze + (1-s) * 1/Zh
where s is the normalized distance/interpolation parameter (between 0 and 1) along the line in screen space, meaning B = s * E + (1-s) * H
Use homogeneous coordinates, which can be linearly interpolated in screen space (for depth and texture): http://www.cs.unc.edu/~olano/papers/2dh-tri/
I am having two Vectors (X,Y,Z), one above Y=0 and one below Y=0.
I want to find the Vector (X,Y,Z) where the line between the two original vectors intersects with the Y=0 level.
How do I do that?
Example Point A:
X = -43.54235
Y = 95.2679138
Z = -98.2120361
Example Point B:
X = -43.54235
Y = 97.23531
Z = -96.24464
These points read from two UnProjections from a users click and I'm trying to target the unprojection to Y=0.
(I found 3D line plane intersection, with simple plane but didn't understand the accepted answer as it's for 2D)
I suspect that by two vectors, you really mean two points, and want to intersect the line connecting those two points with the plane defined by Y=0.
If that's the case, then you could use the definition of a line between two points:
<A + (D - A)*u, B + (E - B)*u, C + (F - C)*u>
Where <A,B,C> is one of your points and <D,E,F> is the other point. u is an undefined scalar that is used to calculate the points along this line.
Since you're intersecting this line with the plane Y=0, you simply need to find the point on the line where the "Y" segment is 0.
Specifically, solve for u in B + (E - B)*u = 0, and then feed that back into the original line equation to find the X and Z components.
The equation for the line is
(x–x1)/(x2–x1) = (y–y1)/(y2–y1) = (z–z1)/(z2–z1)
So making y=0 yields your coordinates for the intersection.
x = -y1 * (x2-x1)/(y2-y1) + x1
and
z = -y1 * (z2-z1) /(y2-y1) + z1
I am working with a hexagonal grid. I have chosen to use this coordinate system because it is quite elegant.
This question talks about generating the coordinates themselves, and is quite useful. My issue now is in converting these coordinates to and from actual pixel coordinates. I am looking for a simple way to find the center of a hexagon with coordinates x,y,z. Assume (0,0) in pixel coordinates is at (0,0,0) in hex coords, and that each hexagon has an edge of length s. It seems to me like x,y, and z should each move my coordinate a certain distance along an axis, but they are interrelated in an odd way I can't quite wrap my head around it.
Bonus points if you can go the other direction and convert any (x,y) point in pixel coordinates to the hex that point belongs in.
For clarity, let the "hexagonal" coordinates be (r,g,b) where r, g, and b are the red, green, and blue coordinates, respectively. The coordinates (r,g,b) and (x,y) are related by the following:
y = 3/2 * s * b
b = 2/3 * y / s
x = sqrt(3) * s * ( b/2 + r)
x = - sqrt(3) * s * ( b/2 + g )
r = (sqrt(3)/3 * x - y/3 ) / s
g = -(sqrt(3)/3 * x + y/3 ) / s
r + b + g = 0
Derivation:
I first noticed that any horizontal row of hexagons (which should have a constant y-coordinate) had a constant b coordinate, so y depended only on b. Each hexagon can be broken into six equilateral triangles with sides of length s; the centers of the hexagons in one row are one and a half side-lengths above/below the centers in the next row (or, perhaps easier to see, the centers in one row are 3 side lengths above/below the centers two rows away), so for each change of 1 in b, y changes 3/2 * s, giving the first formula. Solving for b in terms of y gives the second formula.
The hexagons with a given r coordinate all have centers on a line perpendicular to the r axis at the point on the r axis that is 3/2 * s from the origin (similar to the above derivation of y in terms of b). The r axis has slope -sqrt(3)/3, so a line perpendicular to it has slope sqrt(3); the point on the r axis and on the line has coordinates (3sqrt(3)/4 * s * r, -3/4 * s * r); so an equation in x and y for the line containing the centers of the hexagons with r-coordinate r is y + 3/4 * s * r = sqrt(3) * (x - 3sqrt(3)/4 * s * r). Substituting for y using the first formula and solving for x gives the second formula. (This is not how I actually derived this one, but my derivation was graphical with lots of trial and error and this algebraic method is more concise.)
The set of hexagons with a given r coordinate is the horizontal reflection of the set of hexagons with that g coordinate, so whatever the formula is for the x coordinate in terms of r and b, the x coordinate for that formula with g in place of r will be the opposite. This gives the third formula.
The fourth and fifth formulas come from substituting the second formula for b and solving for r or g in terms of x and y.
The final formula came from observation, verified by algebra with the earlier formulas.