<HTML>
<HEAD>
<TITLE>Re: [vtk-developers] New function: vtkMath::ProjectVector</TITLE>
</HEAD>
<BODY>
<FONT FACE="Calibri, Verdana, Helvetica, Arial"><SPAN STYLE='font-size:11pt'>You can get the magnitude squared of any vector by taking the dot product with itself. That’s basically what you are doing to compute the bSquared variable although I would suggest using vtkMath::Dot(b,b) instead.<BR>
<BR>
-Ken<BR>
<BR>
<BR>
On 9/13/10 2:05 AM, "John Platt" <<a href="jcplatt@dsl.pipex.com">jcplatt@dsl.pipex.com</a>> wrote:<BR>
<BR>
</SPAN></FONT><BLOCKQUOTE><FONT FACE="Calibri, Verdana, Helvetica, Arial"><SPAN STYLE='font-size:11pt'>David,<BR>
<BR>
Perhaps the scale factor could be computed by ..<BR>
<BR>
const double bSquared = b[0]*b[0] + b[1]*b[1] + b[2]*b[2];<BR>
const double scale = bSquared > 0.0 ? vtkMath::Dot(a,b)/bSquared : 0.0;<BR>
<BR>
and then continue to scale b[] without the zero check on b[].<BR>
<BR>
It's your decision if you want a zero b[] to be an error as the algorithm<BR>
should not fail (personally I would let it pass) but it should be documented<BR>
as a precondition.<BR>
<BR>
HTH<BR>
<BR>
John.<BR>
<BR>
<BR>
----- Original Message -----<BR>
From: "David Doria" <<a href="daviddoria+vtk@gmail.com">daviddoria+vtk@gmail.com</a>><BR>
To: "John Platt" <<a href="jcplatt@dsl.pipex.com">jcplatt@dsl.pipex.com</a>><BR>
Cc: "VTK Developers" <<a href="vtk-developers@vtk.org">vtk-developers@vtk.org</a>><BR>
Sent: Monday, September 13, 2010 1:00 AM<BR>
Subject: Re: [vtk-developers] New function: vtkMath::ProjectVector<BR>
<BR>
<BR>
On Sun, Sep 12, 2010 at 7:49 PM, John Platt <<a href="jcplatt@dsl.pipex.com">jcplatt@dsl.pipex.com</a>> wrote:<BR>
> Hi David,<BR>
><BR>
> There could be a quick exit when b[3] is a zero vector to avoid any<BR>
> trouble<BR>
> computing scale.<BR>
><BR>
> There is the potential for round off damage and a small inefficiency by<BR>
> squaring the square root computed by Norm().<BR>
><BR>
> I can't get {25./26., 5./26., 0} to make (1.2, -1.6, 0) in your test<BR>
> program.<BR>
><BR>
> HTH<BR>
><BR>
> John.<BR>
<BR>
Hi John,<BR>
<BR>
Thanks for looking at this. I added the test for an all zero b vector.<BR>
Sorry, it was my mistake in the test. I changed the vectors that the<BR>
test was using but I did not update the text of the error message<BR>
displayed if it failed. The test passes when the projection is the<BR>
vector {25./26., 5./26., 0} (and it did and still does pass for me).<BR>
<BR>
<a href="http://github.com/daviddoria/daviddoria-vtk/commit/7fc33a0ebe7c2b589e62f5db396ec4527ee57f79">http://github.com/daviddoria/daviddoria-vtk/commit/7fc33a0ebe7c2b589e62f5db396ec4527ee57f79</a><BR>
<BR>
Do you have a suggestion for how to overcome the roundoff error and<BR>
inefficiency of the squaring?<BR>
<BR>
Thanks,<BR>
<BR>
David D.<BR>
<BR>
<BR>
_______________________________________________<BR>
Powered by www.kitware.com<BR>
<BR>
Visit other Kitware open-source projects at <a href="http://www.kitware.com/opensource/opensource.html">http://www.kitware.com/opensource/opensource.html</a><BR>
<BR>
Follow this link to subscribe/unsubscribe:<BR>
<a href="http://www.vtk.org/mailman/listinfo/vtk-developers">http://www.vtk.org/mailman/listinfo/vtk-developers</a><BR>
<BR>
<BR>
<BR>
</SPAN></FONT></BLOCKQUOTE><FONT FACE="Calibri, Verdana, Helvetica, Arial"><SPAN STYLE='font-size:11pt'><BR>
</SPAN></FONT><FONT SIZE="2"><FONT FACE="Consolas, Courier New, Courier"><SPAN STYLE='font-size:10pt'><BR>
**** Kenneth Moreland<BR>
*** Sandia National Laboratories<BR>
*********** <BR>
*** *** *** email: <a href="kmorel@sandia.gov">kmorel@sandia.gov</a><BR>
** *** ** phone: (505) 844-8919<BR>
*** web: <a href="http://www.cs.unm.edu/~kmorel">http://www.cs.unm.edu/~kmorel</a><BR>
</SPAN></FONT></FONT><FONT FACE="Calibri, Verdana, Helvetica, Arial"><SPAN STYLE='font-size:11pt'><BR>
</SPAN></FONT>
</BODY>
</HTML>