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

John Platt jcplatt at dsl.pipex.com
Mon Sep 13 04:05:18 EDT 2010


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.





More information about the vtk-developers mailing list