Author Topic: GetSamplePoints problem.  (Read 2723 times)

0 Members and 1 Guest are viewing this topic.

BillZndl

  • Guest
GetSamplePoints problem.
« on: June 09, 2011, 10:52:08 AM »
R2012, VS2010, Win7

GetsamplePoints changed from returing a Point3d[] array to a PointOnCurve3d[] array.
I'm having trouble putting the points into my Point3d[] array that the method returns.

Code: [Select]
                    PointonCurve3d PntEntLst = arc.GetSamplePoints(12);
                    int i = 0;
                    Point3d[] PntLst = null;

                    foreach (PointOnCurve3d p in PntEntLst)
                    {
                        ed.WriteMessage("\nP Type: " + p.GetType().FullName);

                        PntLst.SetValue(p.Point, i); //<--- this seems to prevent the loop from returing anything.

                        i = i + 1;

                        ed.WriteMessage("\nValue of i:" + i.ToString());
                        ed.WriteMessage("\nValue of pnt: " + p.Point);

                    }
ed.WriteMessage("\nLength PnLst : " + PntLst.Length);

if I rem out the PntLst.SetValue(p.Point, i); , the loop returns the messages to the screen with values and types correct.
I've tried PntLst.SetValue((Point3d)p.Point, i);  and several other ways but as soon as I add the Point3d array PntLst the loop returns nothing.



BillZndl

  • Guest
Re: GetSamplePoints problem.
« Reply #1 on: June 09, 2011, 11:28:33 AM »
Just looks like things that worked in net 2.0 don't work anymore.
I was declaring Point3d[] as null before the switch statement
and then using it in each leg of the switch and returning it at the end of the method.
Don't know why but that's what it isolates down to, for now.



Jeff H

  • Needs a day job
  • Posts: 6150
Re: GetSamplePoints problem.
« Reply #2 on: June 09, 2011, 11:32:05 AM »
Need to intialize array

Point3d[] PntLst = new Point3d[12];

******Edit*******

Seems you figured it out

Glenn R

  • Guest
Re: GetSamplePoints problem.
« Reply #3 on: June 09, 2011, 11:33:12 AM »
Off the top of my head, it's probably because you're array is initialised to null and not anything significant.
Something like this perhaps, as you already know the length of the required array:

Code: [Select]
Point3d[] PntLst = new Point3d[PntEntLst.Length];

for (int i = 0; i < PntEntLst.Length; i++)
{
  PntLst[i] = PntEntLst[i].Point;
}


Or something along those lines.

BillZndl

  • Guest
Re: GetSamplePoints problem.
« Reply #4 on: June 09, 2011, 11:56:14 AM »
Yep, thanks all.

I'll just have to declare a temp array in each leg then set the main array to that each leg.



More to come I'm sure.   :kewl:

BillZndl

  • Guest
Re: GetSamplePoints problem.
« Reply #5 on: June 10, 2011, 02:57:46 PM »
Well go figure,
After I got the points problem figured out,
the image in the picture box wouldn't display.
After checking the points, they were way off in the wrong direction.
All I had to do was add the .Negate to the matrix I was using and it works fine now.
May have been a "bug" that was fixed after 2.0 < shrug >.

Code: [Select]
private static Matrix3d PointsToImageMatrix(double SclFac, Point3d p1, Point3d p2)
        {
            Matrix3d MatS = Matrix3d.Scaling(SclFac, p2);                              //scale pointlist to picbox.       
            Matrix3d MatD = Matrix3d.Displacement(p2.GetVectorTo(p1)[color=red].Negate()[/color]);                 //displacement.           
            Matrix3d MatR = Matrix3d.Rotation(Math.PI, new Vector3d(0, 0, 1), p1);     //rotate 180 for picbox.

            return MatS * MatD * MatR;
        }