Computing the distance between points and starting point across a line - vtk

Say we have a line with a starting point p1 and an end point p2. Using vtkMath::Distance2BetweenPoints(point1, point2), how can we measure the distance of each point in the line with respect to the starting point in the line?
The documentation of this function can be found here: http://www.vtk.org/doc/nightly/html/classvtkMath.html#a11944eda4bd17e4e57bcd1e49c2f9446
Thanks.

Distance2BetweenPoints is nothing else than a convenient function for computing (x1-x2)^2 + (y1-y2)^2+(zi-z2)^2
(btw, remember that for getting the actual distance you need the square root).
So you just need to iterate and compute the distance between each point and the starting point (the fact that they are on a line is not relevant).

Related

Is the minimal distance of a line to a point always orthongonal to the line

I have a point and a (curved) line. Now I want to find the distance to the line where the direction from the point to the point on the line stands orthogonal on the line.
Intuitively I think that the shortest connection between the closest point on the line and the point is always orthogonal, but I'm not 100% sure that my geometry intuition is correct. Can you confirm that for finding the orthogonal connection between a point and a point on a line it is enough to check the closed point on the line?
What you wrote can be true, subject to conditions.
Your curve must be either closed, or start/end infinitely far away (like the shape of y=1/x or y=x^2). Otherwise, the closest distance can be to an end point of the curve.
The curve must be smooth. For instance, a triangle is not smooth, the normal is not defined at the 3 vertices and the closest distance can be a distance to the vertex. Another example, cubic Bézier splines may contain a singularity where the normal is not defined, see the top right picture:
Again, closest distance might be a distance to that singularity point.
Also, don’t forget it can be multiple points on the curve with orthogonal connection. You gonna have to find all of them, and use the minimum distance found. Moreover, in some cases “all of them” can be “infinitely many”, if the curve contains a piece of a circular arc.

Calculating an angle relative to a reference line

PLEASE SEE PICTURE -angle relative to baselinewe've been struggling with this for a while. Assuming we have distance between our measurement point P0 and P3-P4 and as also between P0 and our reference line P1-p2. Can we calculate the angle of p3-p4 relative to p1-p2? Once we figure this out, we'll see our to program it for IOS. Thanks for anyone who can point me in the right direction. [PLEASE SEE PICTURE relative angle measurement][2]
If P0 is a known point and P1-P2 and P3-P4 are defined lines in a 2D coordinate system (ie P0 to each line a defined vector) then you can certainly calculate the angle between the two lines. However if all you know is distance from P0 to each line as a function of a point on either line then you cannot calculate the angle distance alone will not give you what you need without some point of reference.

Puzzle: Planar configuration of straight connecting lines

Puzzle : Given an even number of points in general positions on the plane (that is, no three points co-linear), can you partition the points into pairs and connect the two points of each pair with a single straight line such that the straight lines do not overlap?
My Solution : One simple approach (that seems just too simple).
Start with the point with left-most x-coordinate and then draw a line to the next least left-most x-coordinate. Then find the next least pair of points and connect and so on!
Is this correct?
Just tried it! That's one of the solutions!

Find all polygons formed by intersections of lines

I have a maze described by walls as line segments (no given order). Given a point, I need to determine whether its inside the maze or no. Everything is in the Cartezian plane(no discretization).
My idea is to transform the problem as follows:
Given some line segments in the plane, find all polygons with vertices in the endpoints of the given segments and with sides lying on the segments (you can see in the image below that you can't assume the sides will form a subset of segments).
And then just check: if a point is only inside one polygon, then its inside of the maze, otherwise no.
The solution I have in mind would be: hash endpoints and line intersections, and then look for loops.
Any other suggestions?
Thanks!
(ignore the colors in the image)
It is enough to find boundary (outer) polygon. That can be done by finding one point on the boundary and than traversing from that point by segments in one direction. If there are more possibilities to go than choose 'outer' one. Algorithm can be described:
find boundary point
find first direction to go and go to that point
while current point is different than fist one
find next direction to go
go to next point
First point can be find as point with highest Y coordinate, if there are more like that than one with lowest X among them. We can call it upper-left point.
First direction to go: first point is connected to other points and that points have <= Y coordinate, what means that connection segments are below first point. Choose right-most of them.
Next direction to go: current point is reached by some (incoming) segment, next segment to go is furthest away in positive direction from incoming one, what is same as first segment in clock-wise direction from incoming segment.

An algorithm to skip 3D curve points

Currently I am drawing a 3D curve consisting of 1200...1500 straight micro-lines directed by an array of 3D points (x,y,z), but rendering is a bit slow regardless of used technology (Adobe Flash, Three.js).
The curve is a kind of 3D arc with a 180 degree loop at the end, so I thought that skipping some points in places where the curve is more smooth and predictable will speed up rendering.
Could you suggest some algorithm which can determine how close to a straight line the specific piece of 3D curve is?
Update
I tried to make Three.js to render these points as a single curve and it works really fast. But the different pieces of this curve should be differently colored, so I have to draw it as a bunch of separate lines and the only thing I can do to speed it up is to skip every second point in a region where line is close to a straight line.
I can not use OpenGL (WebGL) because not all browsers support it.
The difference between three points and a straight line can be quantified from the distance of the middle one from the line on which the other two rest. Probably getting the two lengths along the line from either end point to the middle one, dividing the distance by both and summing the two results is the easiest way to turn it into a single number.
So:
as the middle point gets closer to the line, the number goes down;
as the line segment grows longer, variations by the mid point need to be proportionally more extreme; and
greater local slope (as if the middle point were very close to either end) produces a greater error.
You can get the distance from a position to a line by obtaining the vector from any point on the line to the position, using the dot product to work out how much of that is movement along the line and then subtracting that from the total. If you don't normalise your vector along the line first you end up having multiplied by the square of it, so no need for a square root operation on that account. Then for the implied length calculation you can just keep and compare all of those as squared.

Resources