## Distance between two line segments defined by sparse points

Given a set S of line segments and an additional segment L, I’m looking for a procedure that determines which of the line segments in S is nearest to L. My first thought was to compute the distance between the points of L and the points of each line segment in S, however it can be tricky as illustrated in the following figure:

Let’s say that L is the blue line, I want my method to point out that the green one is the nearest, but computing the distance between the points in such example may not provide the intended result.

Therefore my question is: which is the simplest (and correct) way to address this problem.

Thank you so much for your help.

## How does this answer for automata and Hamming distance not lead to inconsistencies?

I had already been given the answer by the TA in class, but I don’t understand it. I’m not asking for the answer on a homework problem or anything.

The problem:

The Hamming distance (“distance”) of a word w to v of the same size is the number of positions wherein they differ. The distance between a w and L is the smallest such distance from a word chosen among L.

Let k be a natural number, and L a regular language. L’ is the set of words w at a distance not greater than k from L. Show that L’ is regular.

The way to go about this was to construct an automaton for such an L’, and to do induction on k. If k = 0, then L’ = L0 = L, and M0 = (Q0, E, delta0, q0, F0).

In general

• Q is the set of states for an automaton accepting words with a distance at most k.

• E is the alphabet among all machines and languages.

• d is the tranisition function of Mk,

• q0 is the start state for Mk

• F is the set of final states for Mk.

The answer, according to the TA:

Assuming that the construction is valid for all i <= k, we can form M' as follows:

``````Q' = Q x {0, 1}, and **q'** is an element of Q'

q0' = (q0, 0)

d'((q, 0), a) = {(d(q, a), 0)} u {(d(q, b), 1) | b element of E}

d'((q, 1), a) = {(d(q, a), 1)}

F' = {q' = (q, t) | t = 0 or t = 1}
``````

I really don’t get this. To me, it seems that if I start off with less than k+1 errors then I’ll be in a state (q1, 0) for some q1, and if I read 1 error then I’m put in a state (q2, 1) for some q2. If I am in a state (q1, 1) for some q1 and read anything, then I’ll be in a state (q2, 1) for some q2.

If I start with reading the first letter of any input, then I start in (q0, 0), and if I read one error then I’m in (q1, 1), and if I read 50 errors then I’m in (q, 1) for some q, but if we wanted k to be, say, 5, then I’ve surpassed that.

I’m really confused here. I’d appreciate any help.

Thank you.

## Damage to electronics from lightning strike at a distance

Electromagnetic pulse is said to detsroy electronics. Lightning is a type of EMP. As per my understanding lightning is basically a dielectric breakdown, it can be considered as DC current. Can it or any dielectric breakdown damage electronics from a distance, say 1m, 10 m , 100m or 1 km? If yes, how is that possible, because it cannot induce voltage in any wire as it is DC? Even if it is AC of few Hz, the length of any household wire will be very small as compared to the wavelength, then also there will be huge resistance to any volatge induced.

## Calculate Earth’s distance travelled in a year

This is probably more of a math question than astronomy, but I’d like to know the distance the Earth travels in one revolution around the sun (i.e. a year).

According to the data in Wikipedia, I think there may be several ways for me to calculate this but I’m not sure whether they are correct or how to do them:

1. Calculate by velocity and time: the average velocity is given as $$107200 mathrm{km/h}$$ (a suspiciously round number; imprecise?) and one revolution takes $$365.256363004$$ days. That gives $$text{distance} = 107,200 mathrm{km/h} times (365.256363004 times 24 mathrm h) = 939,731,570.736691 mathrm{km} approx 939.731 mathrm{Gm}$$
2. Calculate by semi-major axis and eccentricity: my math is too weak for that. I searched the web and didn’t find a solution for that (calculating the circumference of an ellipse exactly seems to be a problem?)
3. Any other way using the orbital data given in the Wikipedia article?

In essence, this can be made into a pretty generic question: How do I calculate the distance an object travels in one revolution using the usual orbital parameters?

## A least sized partition of a set under a distance metric

What is the worst case complexity of an algorithm to find a least partition of a set under a distance metric, described as follows:

Input:

• A set $$S={s_1,ldots,s_n}$$, where the elements $$s_i$$ are of some type $$T$$.
• A distance metric $$D:Trightarrow [0, infty)$$.
• A radius $$r:[0, infty)$$

Output: A partition $$S_1,ldots,S_m$$ of $$S$$ such that

• $$S_icap S_j=emptyset, ineq j$$ and
• $$S=cup_{i=1}^m S_i$$ and
• $$D(s,t) leq r$$, $$s,t in S_i$$ and
• There is no other partition with the same properties of size $$m^{prime} < m$$.

NOTE: I am saying “a partition” not “the partition”, because there may be multiple partitions of least size for the same set of points. For example consider $$2 n$$ points on a large circle where the points are spaced such that each pair of points is distance $$r$$ apart. In this case there are $$2 n-1$$ distinct least-sized partitions of minimum size $$n$$.

NOTE: The following algorithm will produce a partition with desired properties except that it is not guaranteed to be least size:

• $$i=1$$
• While $$|S| > 0$$:
• Choose $$e in S$$ and set $$S:=S-{e}$$
• $$S_i={xin S: D(e,x) leq r}$$
• Set $$S:=S setminus S_i$$
• Set $$i:=i+1$$

NOTE: It has been suggested that this is an NP-hard problem, but the above partial solution is $$O(n^2)$$.

NOTE: This problem is an abstraction of this geographic problem.

## What is the inverse square of a distance (Euclidean)?

I’m studying k-nearest neighbor algorithms and the book I’m reading mentions that records are weighted according to their inverse square in order to perform weighted voting.

so I was wondering what do they mean by “inverse square” the example in the book is:

\$text{votes(record)}= frac{1}{d(a,b)^2} = 1/0.004393^2 sim 51,818\$

so does inverse square just mean diving one by the distance of a specific record? any further insight into what that might mean will be greatly appreciated.

## Calculation of relative distance

I have 100 term triplets as shown in the below mentioned figure. Each triplet contains 3 objects namely x, y and z. I want to rank the triplets according to the following two properties.

1. y should be close to both x and z (e.g., Figure (1)). i.e. the closest will be ranked in the top
2. To penalize Y objects which are close to only one object (x or z) but far away from the other object (x or z) (e.g., Figure (2))

Is there any standard metric or any other formula I can use for this?

## Why I can’t calculate the distance between a fixed point and a geometry field of a MySql table using this…

I am not so into database and GIS and I have the following problem.

I have defined this function that return the distance between 2 points in the space represented by 2 point fields:

``````CREATE FUNCTION earth_circle_distance(point1 point, point2 point) RETURNS double
DETERMINISTIC
begin
declare lon1, lon2 double;
declare lat1, lat2 double;
declare td double;
declare d_lat double;
declare d_lon double;
declare a, c, R double;

set lon1 = X(GeomFromText(AsText(point1)));
set lon2 = X(GeomFromText(AsText(point2)));
set lat1 = Y(GeomFromText(AsText(point1)));
set lat2 = Y(GeomFromText(AsText(point2)));

set d_lat = radians(lat2 - lat1);
set d_lon = radians(lon2 - lon1);

set R = 6372.8; -- in kilometers

set a = sin(d_lat / 2.0) * sin(d_lat / 2.0) + sin(d_lon / 2.0) * sin(d_lon / 2.0) * cos(lat1) * cos(lat2);
set c = 2 * asin(sqrt(a));

return R * c;
end
``````

It works pretty fine, I tryied passing to it 2 point defined by:

``````SET @point1= GeomFromText('POINT(41.772683, 12.241714)');
SET @point2 = GeomFromText('POINT(42.1212121, 13.1212121)');
``````

The problem is that I want to use this fucntion into a query to calculate the distance between a setted point and another point represented by a record of my accomodation table.

So I have tryied something like this:

``````SET @fiumicino = GeomFromText('POINT(41.772683, 12.241714)');

SELECT a.accomodation_name as name,
AsText(a.geographical_position) as position,
X(a.geographical_position) as lat,
Y(a.geographical_position) as lon,
earth_circle_distance(@fiumicino, a.geographical_position)
FROM accomodation a
``````

I want to calculate the distance of all the points represented by the geographical_position field of the accomodation table and the setted point @fiumicino.

The data type of the geographical_position field is GEOMETRY (because in Java I have some problem to interact with POINT data type using Hibernate, I can’t change it).

The problem is that performing the previous query is that I obtain the following error message:

``````#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '(a.geographical_position),
@Y(a.geographical_position),
earth_circle_d' at line 3
``````

The problem happens when the earth_circle_distance(@fiumicino, a.geographical_position) is performed.

Infact deleting this statment from my query, so performing this simplified query that don’t calculate the ditance:

``````SET @fiumicino = GeomFromText('POINT(41.772683, 12.241714)');

SELECT a.accomodation_name as name,
AsText(a.geographical_position) as position,
X(a.geographical_position) as lat,
Y(a.geographical_position) as lon
FROM accomodation a

name                            position                    lat                     lon
---------------------------------------------------------------------------------------------------------------------------
Grand Hotel Marina de Ostia     POINT(41.729086 12.278478)  41.729086               12.278478
Motel La Bettola                POINT(41.883991 12.33544)   41.883991               12.33544
HOTEL 1                         POINT(41.82703258287677     12.266217163303374)     41.82703258287677   12.266217163303374
HOTEL 2                         POINT(41.816297452855096 12.239581452630633)        41.816297452855096  12.239581452630633
``````

So, as you can see, the value of a.geographical_position field used into earth_circle_distance(@fiumicino, a.geographical_position) is something like POINT(41.883991 12.33544). But int this way it didn’t work.

Why? What is wrong? What am I missing?

I also retrived the value of the latitude and of the longitude of my point, by @X(a.geographical_position) and @Y(a.geographical_position).

I also thinked that I can try to create a new point with the previous values as second parameter to pass to this earth_circle_distance() function. But I don’t know how exactly do it.

Someone can help me to sove and obtain the distance between the fixed point and the point represented by the a.geographical_position of the current record?

Tnx