There is already an answer for:
What is the correct way if this is incorrect?
You should only ask one question at a time. I'll cover:
Is this correct? Can you prove or disprove it?
Also, it was questioned in comments whether the OP algorithm might be "good enough" even if it isn't the diameter from a curve. Bottom line: you aren't guaranteed to get the two points that are furthest from each other.
Consider the point cloud with exactly four co-planar points, { A, B, C, D }
. AB = AC = r
, BAC = 70
degrees, ABC = ACB = 55
degrees, and D
is halfway along BC
.
Like so:
A
r r
B D C
Bottom line (TLDR;) using OP algorithm: if D
is the random point, the next point is A
, then either B
(or C
: same distance). OP algorithm yields AB
or AC
. However, the longest distance is BC
. The algorithm fails in at least this case.
Math Proof:
- From random point
D
we compare AD
and BD
. AD = r*sin(55)
and BD = DC = r*cos(55)
. Since cos(55) < sin(55)
, AD > BD
and point 2 is A
.
- From
A
we consider AD
and AC
. AC = r
and r > r*sin(55)
, so AC > AD
and the final point is C
(or B
: same distance).
- Final OP diameter is
AC = r
.
However, BC = 2*r*cos(55)
which means BC > r
. The furthest two points from each other are B
and C
, not A
and C
.