[vtk-developers] New function: vtkMath::ProjectVector

Moreland, Kenneth kmorel at sandia.gov
Tue Sep 14 18:37:02 EDT 2010


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.

-Ken


On 9/13/10 2:05 AM, "John Platt" <jcplatt at dsl.pipex.com> wrote:

David,

Perhaps the scale factor could be computed by ..

const double bSquared = b[0]*b[0] + b[1]*b[1] + b[2]*b[2];
const double scale = bSquared > 0.0 ? vtkMath::Dot(a,b)/bSquared : 0.0;

and then continue to scale b[] without the zero check on b[].

It's your decision if you want a zero b[] to be an error as the algorithm
should not fail (personally I would let it pass) but it should be documented
as a precondition.

HTH

John.


----- Original Message -----
From: "David Doria" <daviddoria+vtk at gmail.com>
To: "John Platt" <jcplatt at dsl.pipex.com>
Cc: "VTK Developers" <vtk-developers at vtk.org>
Sent: Monday, September 13, 2010 1:00 AM
Subject: Re: [vtk-developers] New function: vtkMath::ProjectVector


On Sun, Sep 12, 2010 at 7:49 PM, John Platt <jcplatt at dsl.pipex.com> wrote:
> Hi David,
>
> There could be a quick exit when b[3] is a zero vector to avoid any
> trouble
> computing scale.
>
> There is the potential for round off damage and a small inefficiency by
> squaring the square root computed by Norm().
>
> I can't get {25./26., 5./26., 0} to make (1.2, -1.6, 0) in your test
> program.
>
> HTH
>
> John.

Hi John,

Thanks for looking at this. I added the test for an all zero b vector.
Sorry, it was my mistake in the test. I changed the vectors that the
test was using but I did not update the text of the error message
displayed if it failed. The test passes when the projection is the
vector  {25./26., 5./26., 0} (and it did and still does pass for me).

http://github.com/daviddoria/daviddoria-vtk/commit/7fc33a0ebe7c2b589e62f5db396ec4527ee57f79

Do you have a suggestion for how to overcome the roundoff error and
inefficiency of the squaring?

Thanks,

David D.


_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://www.vtk.org/mailman/listinfo/vtk-developers





   ****      Kenneth Moreland
    ***      Sandia National Laboratories
***********
*** *** ***  email: kmorel at sandia.gov
**  ***  **  phone: (505) 844-8919
    ***      web:   http://www.cs.unm.edu/~kmorel

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtk-developers/attachments/20100914/de07e440/attachment.html>


More information about the vtk-developers mailing list