PDA

View Full Version : Simple Geometric Question



GregMalick
08-14-2004, 02:05 PM
Here's a real simple question for someone to answer:

I made a one sided triangle and pressed F2 to center it.
I made an LScript to calculate the average (see below).
The origin & and my calculated center don't seem to be the same (see picture).
What basic concept don't I understand?



pointAve = <0,0,0>;

foreach(poly, polygons) {
for (i=1; i<= poly.pointCount; ++i) pointAve += pointinfo(poly.points[i]);
pointAve /= poly.pointCount;
apoint = addpoint(pointAve);
}

evenflcw
08-14-2004, 03:06 PM
That LWs Center command doesn't calculate the average position of _all_ points, but instead simply determines the highest and lowest (Y), leftmost and rightmost (X), closest and furthest (Z) point of the mesh and centers on each axis based on them. I guess.

Lynx3d
08-14-2004, 03:19 PM
absolutely, you created more or less a weighted sum of all positions. That's not the geometrical center, more like a center of gravity.

Instead just determine the bounding box...
Just pick any point and use it for both corners of the bounding box. Then go through each point and check if it is outside, if so increase the bbox so that every dimension lies within it.
Then just add the two corners and divide by 2, ready is your center.

GregMalick
08-14-2004, 03:20 PM
Yes, it does appear that's the answer.
In other words, it's the center of the Bounding Box.;)

I've been playing with poly normals too and they seem to be based upon a similar "center" calculation. (see attached).

huh...

GregMalick
08-14-2004, 03:21 PM
oops

Lynx3d
08-15-2004, 04:09 AM
The normal vector is the cross product of the two vectors first->second and first->last point of the polygon.

It doesn't really have a position, it's just a direction.
I don't know how Modeler calculates the point to draw the normal vector off, but it does not depend on all points of a polygon with more than 3 points....doesn't seem to be the middle of the bounding box either because it sometimes jumps when you move a point...but as said the position of the normal vector has no meaning.

GregMalick
08-15-2004, 10:26 AM
yes, a polygons normal is really a direction, but the polynormal function in LScript returns a point. It seems to be hovering above the point that Modeler considered the center when you use F2 (center).

Interesting ... I just knifed and added points and even moving the entire triangle and the polynormal function still returns a point hovering above the origin. Obviously it's meant to be displaced whever you need it.

So it was a simply an F2 coincidence.:p

Lynx3d
08-15-2004, 11:28 AM
Originally posted by GregMalick
yes, a polygons normal is really a direction, but the polynormal function in LScript returns a point.

Err...no, it returns a vector...the normal direction.
A "point" really just is a vector too, the vector from origin to the point coordinates.


Originally posted by GregMalick
It seems to be hovering above the point that Modeler considered the center when you use F2 (center).

Interesting ... I just knifed and added points and even moving the entire triangle and the polynormal function still returns a point hovering above the origin. Obviously it's meant to be displaced whever you need it.

So it was a simply an F2 coincidence.:p

That's because you interpreted it as point coordinate, which does not apply here.
Perhaps try the following: Calculate the average point position again of an arbitrarily rotated/moved polygon (like you did in the very first post) and add a point there.
Then add the normal vector to the position you just calculated, and add a second point there.
Create a polyline between the two points you should see that the normal is a "direction"...

GregMalick
08-15-2004, 06:00 PM
I see what you mean... thanks for clarifying the distinction :)