[vtkusers] Distance between points
Matias Montroull
matimontg at gmail.com
Tue Jan 14 19:03:56 EST 2014
It is weird that it doesn't work in ActiViz... It's the same code, maybe it
is the overload function you mentioned?
On Tue, Jan 14, 2014 at 8:58 PM, David Gobbi <david.gobbi at gmail.com> wrote:
> I just tried it in Python, and it works there just fine. And you can
> be sure that it works in C++, because it is one of the most-used
> methods in VTK, and hundreds of the VTK tests would fail if it was
> giving the wrong answer.
>
> The distances that I get are:
>
> p0 = (10.2, 20.7, 10.4)
> p1 = (10.5, 20.5, 10.8)
> vtkMath.Distance2BetweenPoints(p0, p1)
> 0.29000000000000042
> math.sqrt(vtk.vtkMath.Distance2BetweenPoints(p0, p1))
> 0.53851648071345082
>
>
> On Tue, Jan 14, 2014 at 4:53 PM, Matias Montroull <matimontg at gmail.com>
> wrote:
> > Thanks, I will take into account your suggestion.
> >
> > Can you run the code with those point samples and tell me what's the
> > distance you get? I'd like to ensure it works in C++ and then figure out
> how
> > to make it work in ActiViz..
> >
> > Thanks,
> >
> >
> > On Tue, Jan 14, 2014 at 8:48 PM, David Gobbi <david.gobbi at gmail.com>
> wrote:
> >>
> >> Hi Matias,
> >>
> >> I don't use Activiz, but something about your code confuses me:
> >> In C++, Distance2BetweenPoints is overloaded for float and double:
> >>
> >> float Distance2BetweenPoints(const float x[3], const float y[3])
> >> double Distance2BetweenPoints(const double x[3], const double y[3])
> >>
> >> So how does Activiz know which one of these methods to call?
> >> If it passes a "double" IntPtr to the float-overloaded method, then the
> >> result is definitely going to be wrong.
> >>
> >> Also: I suggest that you include "Activiz" or "C#" in the subject line
> >> of all your emails to the list. That will help to attract the attention
> >> of
> >> other Activis users, and they are the ones who are most likely to know
> >> the answers to questions like this one.
> >>
> >> David
> >>
> >>
> >>
> >>
> >> On Tue, Jan 14, 2014 at 4:18 PM, Matias Montroull <matimontg at gmail.com>
> >> wrote:
> >> > Hi,
> >> >
> >> > I'm running this code and I get distance "infinity"... If I change to
> >> > lower
> >> > values (1 digit) then it gives a distance..
> >> > Why?
> >> >
> >> > double[] p0 = new double[] { 10.2, 20.7, 10.4 };
> >> > double[] p1 = new double[] { 10.5, 20.5, 10.8};
> >> >
> >> > IntPtr pP0 = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(double)) *
> >> > 3);
> >> > IntPtr pP1 = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(double)) *
> >> > 3);
> >> > Marshal.Copy(p0, 0, pP0, 3);
> >> > Marshal.Copy(p1, 0, pP1, 3);
> >> >
> >> > // Find the squared distance between the points.
> >> > double squaredDistance = vtkMath.Distance2BetweenPoints(pP0, pP1);
> >> >
> >> > // Take the square root to get the Euclidean distance between the
> >> > points.
> >> > double distance = Math.Sqrt(squaredDistance);
> >> >
> >> > // Output the results.
> >> > Console.WriteLine("SquaredDistance = " + squaredDistance);
> >> > Console.WriteLine("Distance = " + distance);
> >> > Marshal.FreeHGlobal(pP0);
> >> > Marshal.FreeHGlobal(pP1);
> >
> >
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20140114/a5d7bc61/attachment.html>
More information about the vtkusers
mailing list