I have one start point x0,y0,z0 and two angles. Theta(polar(0-180)) and Phi(azimuth (0-360)). And now I need to find direction of vector of reflected line 3d space box with parameters (4,5,6)
I tried to calculate using geometry formula and use cos and sin, adjacent, opposite. But it gave me wrong answer for my further cycle calculation I suppose I need some equation to write. Some kind of i, j, k. I could not calculate slope as I don’t have enough input.
I have a line and point (2D).
Ok, using Paul Bourke formula I can get the distance of ortogonal projection of point to the line.
( Also I can know if the solution is or not inside the segment of line. )
OK, But I'd like to know if the point is at right or left side relative to the line direction.
I can get the angle between line and ortogonal line using
Math.acos (crossproduct/moduleProduct) but crossproduct is zero so I can't use it...
Any idea ? Have to use trigonometric approach or maybe is there a trick using vector data ?
Th. in advance,
You can calculate 2d vectors cross product and look at its sign.
Given two vectors v1 and v2 you can calculate 2d cross product as (v1.X*v2.Y) - (v1.Y*v2.X)
If you have point (x, y) and line (x0, y0)-(x1, y1) then ((x-x0)*(y1-y0)) - ((y-y0)*(x1-x0)) is 2d vector cross product. It will be negative if the point is in the left hemiplane.
I want to know if the centroid of a plane can actually be treated as a point on the plane.I have a few points on the plane from which i deduced the centroid.I would like to know if i substitute this in the plane equation will it be valid.
Thanks,
Harsha.
More of a math question. Answer will depend on which definition of centroid you want. If you define the centroid as the intersection of straight lines that divide the plane in 2 by moment, then clearly every line is in the plane so all their intersections must also be.
The correct way to interpolate between two points on a sphere is using slerp.
How would one interpolate between more than two points on a sphere? So summing a set of points with different weights on the surface of a sphere?
Simply summing the points multiplied by their weights and then normalising the result is not accurate enough when the angles are large. We need 'true' spherical interpolation.
I asked this question on math.stackexchange.com, and someone found a paper that describes exactly this. Here it is: Spherical Averages and Applications to Spherical Splines and Interpolation
The problem I see is:
Slerp gives constant velocity. That is, a given increment in your interpolation parameter gives you the same distance on the sphere, regardless of where you are on the [0,1] range.
Unfortunately, because the sphere is curved, you can't do this for more than one interpolation parameter. Either you need to give up constant velocity, or give up interpolating with more than one parameter.
You may be able to find an interpolation function that isn't constant velocity that nonetheless satisfies your requirements. But because of the above problem, I don't think it will correspond directly and symmetrically to the 1-D slerp.
I have a set of points that form a path. I would like to determine the minimum distance from any given point to this path. The path might look something like this:
points = [
[50, 58],
[53, 67],
[59, 82],
[64, 75],
[75, 73]
];
where the first value is the x coordinate and the second the y coordinate. The path is open ended (it will not form a closed loop) and is made of straight segments between the points.
So, given a point, eg. [90, 84], how to calculate the shortest distance from that point to the path?
I'm not necessarily looking for a complete solution, but any pointers and ideas will be appreciated.
It is possible to construct pathological cases in which the closest line segment to a point P connects two points which are themselves farther from P than any other points in the path. Therefore, unless I am missing something very subtle, you must calculate the distance to each line segment to get the shortest distance to the path.
Here is a simple example:
(5,1)-(4,2)-(1,3)-(20,3)-(15,2)-(14,1)
Given point (10,1), the closest distance to the path would be to the point (10,3), which is along the line segment (1,3)-(20,3), but those two points are farther from (10,1) than any other point in the path.
So I don't believe there are any shortcuts to the naïve algorithm of finding the distance to each line segment and taking the minimum.
The best thing would be to find the closest point from a line (making the path) measure the distance and move on along the path (and store the point for shortest distance).
The distance from a point C to a line segment AB is the area of the parallelogram ABCC'.
So, I just though about it for a second. erekalper already posted the distance between a point and a line. However, the problem with this formula is that it assumes the line has infinite length, which is not the case for your problem. Just an example for the problem: Assume a simple line that goes from (0,0) to (0,1) and a point with coordinates (0,10). The formula posted above would return o distance of 0, because if you extend the line it would hit the point. Unfortunately, in your case the line ends at (0,1), thus the distance is actually 9.
Thus my algorithm would be: Check if the angles at the endpoints of your lines are <= 90°. If so, the shortest distance for this path will be computable by the formula already posted. If not, the shortest distance is the distance to one of the endpoints. Do this for all parts of the path, choose the minimum
The distance between a point and a line is given by:
d = |(x_2 - x_1)(y_1 - y_0) - (x_1 - x_0)(y_2 - y_1)| / sqrt((x_2 - x_1)^2 - (y_2 - y_1)^2),
which is an expansion of the dot product, where (x_0, y_0) are the coordinates of the point, and (x_1, y_1) & (x_2, y_2) are the endpoints of the line.
It would be pretty simple to calculate this for each set of points, and then just determine which one is the lowest. I'm not unconvinced there's not a more elegant way to do so, but I'm not aware of it. Though I'd love to see if someone here answers with one!
Edit: Sorry that the math in here looks so messy without formatting. Here's an image of what this equation looks like, done nicely:
(from MathWorld - A Wolfram Web Resource: wolfram.com)
Another edit: As Chris pointed out in his post, this doesn't work if the points are in-line, i.e., if the line is defined by (0,0)-(0,1) and the point by (0,10). Like he explains, you need to check to make sure that the point being looked at isn't actually on the "extended path" of line itself. If it is, then it's just the distance between the closer endpoint and the point. All credit to Chris!
First you need to find out shortest distance to each line segment and then you choose the smallest distance. When you calculate the shortest distance, you need to find out the nearest point in the line segment. If the nearest point is not between the start and end point, you must use the distance to start or end point (whichever is the nearest).
This page has some formulas that you are likely to need.
You need to use linear algebra (shivers) to calculate the distance from the point to each of the lines.
Here is a link to an article that describes the math: Link
And here is a pretty good library. You need to look at the methods called PointSegmentDistance. A segment is apparently a line that begins at one point and ends at the second point, whereas a line has two points but continue in infinity.