<div dir="ltr">I get 6.6225 and "Infinity"...</div><div class="gmail_extra"><br><br><div class="gmail_quote">On Tue, Jan 14, 2014 at 9:21 PM, David Gobbi <span dir="ltr"><<a href="mailto:david.gobbi@gmail.com" target="_blank">david.gobbi@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">You should try these other math methods to see if they also give<br>
incorrect results:<br>
<br>
double dotprod = vtkMath.Dot(pP0, pP1);<br>
double norm = vtkMath.Norm(pP0);<br>
<br>
For your values of p0 and p1, they should return:<br>
dotprod: 643.77<br>
norm: 25.3118549300520<br>
<div class="HOEnZb"><div class="h5"><br>
On Tue, Jan 14, 2014 at 5:03 PM, Matias Montroull <<a href="mailto:matimontg@gmail.com">matimontg@gmail.com</a>> wrote:<br>
> It is weird that it doesn't work in ActiViz... It's the same code, maybe it<br>
> is the overload function you mentioned?<br>
><br>
><br>
> On Tue, Jan 14, 2014 at 8:58 PM, David Gobbi <<a href="mailto:david.gobbi@gmail.com">david.gobbi@gmail.com</a>> wrote:<br>
>><br>
>> I just tried it in Python, and it works there just fine. And you can<br>
>> be sure that it works in C++, because it is one of the most-used<br>
>> methods in VTK, and hundreds of the VTK tests would fail if it was<br>
>> giving the wrong answer.<br>
>><br>
>> The distances that I get are:<br>
>><br>
>> p0 = (10.2, 20.7, 10.4)<br>
>> p1 = (10.5, 20.5, 10.8)<br>
>> vtkMath.Distance2BetweenPoints(p0, p1)<br>
>> 0.29000000000000042<br>
>> math.sqrt(vtk.vtkMath.Distance2BetweenPoints(p0, p1))<br>
>> 0.53851648071345082<br>
>><br>
>><br>
>> On Tue, Jan 14, 2014 at 4:53 PM, Matias Montroull <<a href="mailto:matimontg@gmail.com">matimontg@gmail.com</a>><br>
>> wrote:<br>
>> > Thanks, I will take into account your suggestion.<br>
>> ><br>
>> > Can you run the code with those point samples and tell me what's the<br>
>> > distance you get? I'd like to ensure it works in C++ and then figure out<br>
>> > how<br>
>> > to make it work in ActiViz..<br>
>> ><br>
>> > Thanks,<br>
>> ><br>
>> ><br>
>> > On Tue, Jan 14, 2014 at 8:48 PM, David Gobbi <<a href="mailto:david.gobbi@gmail.com">david.gobbi@gmail.com</a>><br>
>> > wrote:<br>
>> >><br>
>> >> Hi Matias,<br>
>> >><br>
>> >> I don't use Activiz, but something about your code confuses me:<br>
>> >> In C++, Distance2BetweenPoints is overloaded for float and double:<br>
>> >><br>
>> >> float Distance2BetweenPoints(const float x[3], const float y[3])<br>
>> >> double Distance2BetweenPoints(const double x[3], const double y[3])<br>
>> >><br>
>> >> So how does Activiz know which one of these methods to call?<br>
>> >> If it passes a "double" IntPtr to the float-overloaded method, then the<br>
>> >> result is definitely going to be wrong.<br>
>> >><br>
>> >> Also: I suggest that you include "Activiz" or "C#" in the subject line<br>
>> >> of all your emails to the list. That will help to attract the<br>
>> >> attention<br>
>> >> of<br>
>> >> other Activis users, and they are the ones who are most likely to know<br>
>> >> the answers to questions like this one.<br>
>> >><br>
>> >> David<br>
>> >><br>
>> >><br>
>> >><br>
>> >><br>
>> >> On Tue, Jan 14, 2014 at 4:18 PM, Matias Montroull <<a href="mailto:matimontg@gmail.com">matimontg@gmail.com</a>><br>
>> >> wrote:<br>
>> >> > Hi,<br>
>> >> ><br>
>> >> > I'm running this code and I get distance "infinity"... If I change to<br>
>> >> > lower<br>
>> >> > values (1 digit) then it gives a distance..<br>
>> >> > Why?<br>
>> >> ><br>
>> >> > double[] p0 = new double[] { 10.2, 20.7, 10.4 };<br>
>> >> > double[] p1 = new double[] { 10.5, 20.5, 10.8};<br>
>> >> ><br>
>> >> > IntPtr pP0 = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(double)) *<br>
>> >> > 3);<br>
>> >> > IntPtr pP1 = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(double)) *<br>
>> >> > 3);<br>
>> >> > Marshal.Copy(p0, 0, pP0, 3);<br>
>> >> > Marshal.Copy(p1, 0, pP1, 3);<br>
>> >> ><br>
>> >> > // Find the squared distance between the points.<br>
>> >> > double squaredDistance = vtkMath.Distance2BetweenPoints(pP0, pP1);<br>
>> >> ><br>
>> >> > // Take the square root to get the Euclidean distance between the<br>
>> >> > points.<br>
>> >> > double distance = Math.Sqrt(squaredDistance);<br>
>> >> ><br>
>> >> > // Output the results.<br>
>> >> > Console.WriteLine("SquaredDistance = " + squaredDistance);<br>
>> >> > Console.WriteLine("Distance = " + distance);<br>
>> >> > Marshal.FreeHGlobal(pP0);<br>
>> >> > Marshal.FreeHGlobal(pP1);<br>
>> ><br>
>> ><br>
><br>
><br>
</div></div></blockquote></div><br></div>