Author Topic: New point planear to original points  (Read 3283 times)

0 Members and 1 Guest are viewing this topic.

DaveW

  • Guest
New point planear to original points
« on: September 05, 2006, 03:12:21 PM »
I have been trying to get around ACAD's collinear bug.

If I have line, I know I can get the Double values of X's,Y's and Z's of of the StartPoint, EndPoint and the Normal.

ACAD's help says, "You can add this normal vector to a point to obtain another point."


I can really use another point that is planear to the XY plane of the start and end points of a line based on it's current normal, but is not collinear. The new point should be about the same distance away from the start point as the end point is from the start point.

Does anyone have some sample code that does this? I have been pullingmy hair out all day.


Thanks,

Dave
« Last Edit: September 05, 2006, 03:14:00 PM by DaveW »

DaveW

  • Guest
Re: New point planear to original points
« Reply #1 on: September 05, 2006, 04:24:52 PM »
Here is an example of what I am dealing with:

Command: align
Select objects: all 13 found
Select objects:
Specify first source point: -13.073282044755,77.307053104084,105.082384708192
Specify first destination point: 0,0,0
Specify second source point: -13.073282044755,71.945120358405,109.122890845077
Specify second destination point: 1000,0,0
Specify third source point or <continue>:
-13.575129999524,-87772.9344788884,66304.2898050485
The 3 source points are collinear.


The distances between the first two points and the last point are so far away from the third that ACAD screws up.

I even when ahead and added this function of ACAD newsgroup to check if I am seeing things, but it too says they are not collinear.
Code: [Select]
Public Function Colly(B As Variant, M As Variant, E As Variant, Optional Tolerance As Double) As Boolean
'Gives true if three points B(egin), M(iddle) and E(nd) are collinear
'if d(B,E)= d(B,M) + d(M,E)

Dim i As Integer, dBM As Double, dME As Double, dBE As Double

For i = 0 To UBound(B) 'Assuming all are 2D or all are 3D
dBM = dBM + (B(i) - M(i)) ^ 2
dME = dME + (M(i) - E(i)) ^ 2
dBE = dBE + (B(i) - E(i)) ^ 2
Next i
If Abs(Sqr(dBE) - Sqr(dBM) - Sqr(dME)) < Tolerance Then Colly = True _
Else Colly = False

End Function
« Last Edit: September 05, 2006, 04:27:46 PM by DaveW »

DaveW

  • Guest
Re: New point planear to original points
« Reply #2 on: September 05, 2006, 05:11:10 PM »
The only solution I have found is to get the midpoint of the line, measure it, then get the midpoint from the startpoint to the last midpoint, and repeat, until the vale is less then ten. Then use the startpoing and midpoint of the a line smaller then 10 and ALSO do this procesure to another line and use its mide point, once smaller then 10, for the third alin point.

OMG!

MickD

  • Gator
  • Posts: 3315
  • (x-in)->[process]->(y-out)
Re: New point planear to original points
« Reply #3 on: September 05, 2006, 06:20:06 PM »
you can set the ucs to the ocs of the line, ie -
xvec = line.normal
yvec = normalise(line.ep-line.sp)
zvec = xvec.crossproduct(yvec)

use these to set your new ucs then you can create a new point (0,linelength,0) in that ucs that will be the lines length along the xaxis in the plane of the line.
hth,
Mick.
Forth is like the Tao: it is a Way, and is realized when followed.
Its fragility is its strength; its simplicity is its direction - Michael Ham

Lao Tzu: “To attain knowledge, add things
every day; to obtain wisdom, remove things every day.”

DaveW

  • Guest
Re: New point planear to original points
« Reply #4 on: September 05, 2006, 10:42:09 PM »
Thanks Mick,

But I have no idea of how to do what you are saying.

I ended up doing this:
I have two lines that have been retrieved from the same planer region that has been exploded. I divide the first lines lenth until it is less then 10.
I do the same for the second line. I am already sure they are not collinear, as I make sure line ones handle is not line twos handle and I create a circle and rays and check for intersectwith.
I then use the start and end points of the first line for the first two align points and either the start or endpoint of the second line for the third align point.

It works! It is brute force and anything but eligant. But I had to ge it done and I had a feeling I was not going to endstand what you were going to say. :) I really dont.

You wrote this:
xvec = line.normal
yvec = normalise(line.ep-line.sp)
zvec = xvec.crossproduct(yvec)

xvec = line.normal <-- I beieve this is a three elemnt array of doubles for x, y and z.

yvec = normalise(line.ep-line.sp) <-- no idea at all.
zvec = xvec.crossproduct(yvec) <-- no idea at all.

I can't post my existing code as it way to big.

Thanks,

Dave
« Last Edit: September 05, 2006, 10:50:31 PM by DaveW »

MickD

  • Gator
  • Posts: 3315
  • (x-in)->[process]->(y-out)
Re: New point planear to original points
« Reply #5 on: September 06, 2006, 12:15:48 AM »
Ahh, you are trying to do an 'align' in code yes?

xvec etc are vectors which are an array of 3 doubles as you say.

you create other vectors by subtracting or adding other vectors. The piccy below explains it in 2d, 3d is just as easy.
once you have at least two vectors you can create a ucs by a bit of simple vector math.

If you are doing an align you can create a vector from your line, then create another vector from the lines normal which is multiplied by the lines length. Add the new vec to the vec created by the lines sp and you will have 2 lines perp to each other for use with alignment.
I'll try to draw another piccy.
Forth is like the Tao: it is a Way, and is realized when followed.
Its fragility is its strength; its simplicity is its direction - Michael Ham

Lao Tzu: “To attain knowledge, add things
every day; to obtain wisdom, remove things every day.”

MickD

  • Gator
  • Posts: 3315
  • (x-in)->[process]->(y-out)
Re: New point planear to original points
« Reply #6 on: September 06, 2006, 12:26:23 AM »
a 2d demo of creating the new point piccies

The principals are the same with 3d and will work regardless of where the lines normal is pointing. a vector plus another vector produce a third vector. The values of this vector is actually the new point values.
This is the reason vectors can become confusing,  they can be confused with points very easily because two vectors can have exactly the same values but be located in 2 different places (ie. they were calculated differently using different sp and ep's say) :-o

The best way to understand is to do some very simple maths in 2d to 'proof' the outcome and it will become clear.
« Last Edit: September 06, 2006, 12:37:07 AM by MickD »
Forth is like the Tao: it is a Way, and is realized when followed.
Its fragility is its strength; its simplicity is its direction - Michael Ham

Lao Tzu: “To attain knowledge, add things
every day; to obtain wisdom, remove things every day.”

DaveW

  • Guest
Re: New point planear to original points
« Reply #7 on: September 06, 2006, 04:48:04 AM »
I think I am beginning to understand.

First of all...

SP = StartPoint
EP = EndPoint
NP = NewPoint

By subtracting the startpoint from the endpoint of a line we produce vector

We can also produce a vector from the normal of the line, but we multiply it by the lines length. My guess is that the other vector retrieved by doing subtraction is based on the lines length and we want the second vector to share the same ratio.


Is this correct so far?

Thanks a bunch


« Last Edit: September 06, 2006, 04:53:31 AM by DaveW »

MickD

  • Gator
  • Posts: 3315
  • (x-in)->[process]->(y-out)
Re: New point planear to original points
« Reply #8 on: September 06, 2006, 05:03:21 AM »
Yes!
sorry ep/sp etc. wasn't so clear Dave.

every point in space can be represented as a vector so the sp and ep can both be used as vectors to do some simple vector math. By adding/subtracting vectors you produce a new vector whose tail (sp) starts at the origin and whose head (ep) finishes at the new point.

Like I said, if you draw a 2d grid and keep the numbers simple it's easy ro visually see the calc's and the outcome.

Note that we didn't need to lengthen the lines normal, we could've just added it to the sp and produced another point albeit close to the sp (only 1 unit away). I lengthened the normal so the 3 points would be the same ratio apart which is what I think you are trying to acheive.
Forth is like the Tao: it is a Way, and is realized when followed.
Its fragility is its strength; its simplicity is its direction - Michael Ham

Lao Tzu: “To attain knowledge, add things
every day; to obtain wisdom, remove things every day.”

DaveW

  • Guest
Re: New point planear to original points
« Reply #9 on: September 06, 2006, 05:08:01 AM »
Cool Mick.

It is 2am here. Let me chew on this for a day or so and then see what I can do then.

I have a feeling it is going to quite a bit more, but at least I will understand completely then.

Thank You.

MickD

  • Gator
  • Posts: 3315
  • (x-in)->[process]->(y-out)
Re: New point planear to original points
« Reply #10 on: September 06, 2006, 05:11:58 AM »
no prob's. If I get time I'll see if I can punch out some code, it will be in C# though...I wouldn't know where to start with vb/a :)
Forth is like the Tao: it is a Way, and is realized when followed.
Its fragility is its strength; its simplicity is its direction - Michael Ham

Lao Tzu: “To attain knowledge, add things
every day; to obtain wisdom, remove things every day.”

DaveW

  • Guest
Re: New point planear to original points
« Reply #11 on: September 06, 2006, 05:13:34 AM »
I will share whatever I come up with in VB.

DaveW

  • Guest
Re: New point planear to original points
« Reply #12 on: September 06, 2006, 10:22:38 AM »
This will get things squared up to the WCS. It is not my final code, but the basics are here.

The reason this is not so important to everyone else is that even after the solid is square with the WCS, you still have to rotate it so that you align the proper x, y and z axis with their respective length, width and thickness counterparts. Being as no 3D entity in any cad engine in the world has complete orientation information, there is no way to finish the rotating or aligning the object. The rest of the needed data is not there. I can do it, but I have patented the only way possible around the problem. Licensing is cheap ;) Everyone else decided to drive the drawing with parametrics and formula. At that level, the graphical entites mean nothing, as they are just a result of the underlying database/parametric engine. That approach can work, but it is never really Design/Build. I have my share of different problems, this is for sure, but doing custom stuff is a good 100 times faster then the best parametric software out there.

Thanks again Mick. You are a gem.

« Last Edit: September 12, 2006, 11:43:32 PM by DaveW »

Cathy

  • Bull Frog
  • Posts: 251
Re: New point planear to original points
« Reply #13 on: September 06, 2006, 03:52:54 PM »
As a total aside, it does look like your 3 source points are pretty dang close to colinear.  Using the Colly function that you downloaded from the acad newsgroups, I had to set the tolerance to something like .000000001 to get it to report not colinear.  With a tolerance of .000001 they are colinear. 

DaveW

  • Guest
Re: New point planear to original points
« Reply #14 on: September 06, 2006, 05:34:43 PM »
That is funny Cathy. They are nothing close. Even so, that utility I did not adjust. 0 is 0 and that is what I used in the function.

Here is the deal. The 3D solid that was exploded and the lines were retrieved from was, I believe, 2" x 3/4" x 5000" So I had a ratio of 5000 to 3/4, maybe. Acad will fail, at about 220 to 1. It was an exaggeration test part to reproduce the error easily. The exact number is somewhere in between  223.6 and 223.61 to 1 ratio.


Try this:
If you draw a line.....
Starting at the first specified source point, "10.3688159,-30.95757643,34.08858268"
Then the second specified source point, "-10.3688159,-30.95757643,81.91141732"
Then the third specified source point, "-10.56566629,-30.95757643,81.91141732"

you will get an inverted "L" in modelspace.

Now try to align it with:
First destination point: 0,0,0
Second destination point: 1000,0,0
Third destination point:  0,1000,0

Seriously, I think some programmer used an existing error message for a known bug, but never wrote the correct error message to hide fact he had not fixed his bug or actually forget to fix it.

All said and done, I forced the issue and it works. I have again found another way, thanks to Mick, and if successful in testing, this new way will much faster and more reliable.

Take care,

Dave