Normal vector from 2 3d points - vector

Is it possible to define the normal of an oriented plane from 2 3D points-p1,p2?
If so, is it n=cross(p2,p1)~matlab~.Or can it be n=p2-p1?? I found the second way and i want to know if just the deduction is the normal of a plane(unknown plane).
For example i have the p1,p2 points.I want to find the normal from p2->p1 for a plane fixed at p2.

Related

How many points define a cylinder?

It is known that 4 non-collinear, non-coplanar 3D points define a 3D sphere.
Is there an equivalent property/theorem for cylinder?
For cylinder you need 5 points. But I am not EXACTLY sure if 5 points uniquely defines a cylinder.
Following references justifies this:
http://library.wolfram.com/infocenter/Conferences/7521/cylinder_5_points_computation.pdf
A cylinder has 5 degrees of freedom: 4 for the axis (a line in 3D space), 1 for the radius, so in principle 5 points are required and enough.
But there can be several solutions: taking five point that form a regular bipyramid (two tetrahedra with a common base), there are 6 solutions, by symmetry.
This question is much more interesting than it looks like at a first look.
It is relatively easy to see how 5 points define a cylinder but not uniquely:
you can pick 3 of such points to define a circular cross section and let the other two define the bases. However it is not difficult to see that the choice of the three first points is not unique. It also depends on whether "define" means that the points have to lie on the surface (in which case the two last point have to lie inside the unbounded cylinder defined by the previous three) or not.
I think there is no simple elegant statement like in the case of the sphere.
For a finite cylinder you need a total of 7 parameters.
A 3D line needs 4 parameters (minimum distance from origin, and 3 for orientation). Then from the point closest to the origin you need 2 distances defining the beginning and end of the cylinder. One more parameter is needed for the radius, and voila, you have a 3D cylinder in space defined.
You can also use two 3D points plus a radius which also needs 7 parameters.
For in infinite cylinder you need 5 parameters. 4 for the line and 1 for the radius.
Sticking to the exact vocabulary of the question, you only need two points (really one point and a scalar for the radius) for a sphere.
A cylinder needs no more that 3 points. Two to define the axis and end points, plus a 3rd (really, 2 points and a scalar) to get the radius.

Simple 2D Plane Trajectory with Bezier Curve

Hello and Happy New Year !
Let me begin with the strict facts instead of writing the whole scenario here.
This is what i have:
A plane in 2D Space (X,Y)
A destination this plane has to fly to in 2D space (X,Y)
A bezier curve class that generates the bezier from 4 points (A,B,C,D)
This is what i need to do:
When user clicks on the space in X', Y' i need to generate a bezier curve
for this plane to fly there.
These are some assumptions:
It is known that plane can't rotate in one place, it has to make some minimal turn
It is known that when destination is in front of the plane it doesn't make any turn
Bezier curve has to be calculated from 4 points where
point A = actual plane position
point B = actual plane position + actual plane direction * 2 (so it goes forward a bit ? )
point C = needs to be calculated
point D = plane destination
Here are few of those scenarios drawn:
Question:
How do i calculate this bezier curve, i already have point A,D but i need those B,C to make this turn proper.
How can i characterize this bezier so that let's say planeA has smaller turns than planeB ?
I almost had it, but almost is nothing in this case so i better rewrite this with your help.
Thanks for any help with this, i am scratching my head with this and found it's not that easy i was thinking... or ?
The point B that you described ("actual plane position + actual plane direction") would work quite well. How far you go along the plane direction will adjust when the plane begins its turn.
For point C, setting it to be same as point D (the destination) will work quite well.
As for turning rates, I'm not sure you're going to get much control using a (cubic) bezier curve. They are all about location and direction, with nothing to tweak the second order curvature. Adjusting point B might be a good compromise, but it's more adjusting reaction time and path rather than turning rate.

Sphere that surely encompass given list of points [points are with x, y and z co-ordinate]

I am trying to find sphere that surly encompasses given list of points.
Points will have x, y and z co-ordinate[Points are in 3D].
Actually I am trying to find new three points based on given list of points by some calculations like find MinX,MaxX ,MinY,MaxY,and MinZ and MaxZ and do some operation and find new three points
And I will draw sphere from these three points.
And I will also taking all these three points on the diameter of sphere so I have a unique sphere.
Is there any standard way for finding encompassing sphere of given list of points?
Yes, the standard algorithm is Welzl's algorithm (assuming you want the minimal sphere around your points). Particularly the improved version of Gaertner is very useful, robust and numerically stable! It handles all the degenerate cases well too.
At its core, the algorithm permutes the points (randomly) to find the 1-4 points that lie on the boundary of the sphere. It's basically a clever trial-and-error algorithm. From these points, you can find the center by finding a point that has the same distance to all those points. Gärtner's version uses an improved numerical device to find the center. Also, it employs an extra pivoting step that presumably makes the algorithm work better for a large number of input points.
If all you want is a sphere around three points, I suggest you still use Gärtners "device" to compute the circumsphere of the triangle. Otherwise, the method will probably degenerate easily (i.e. when the triangle is very flat).
Do you need 3 points, or any number of points?
If you only need the answer for 3 points, each pair of points defines a line segment. Take the longest line segment. Take a sphere centered at the middle of that line segment, whose radius is half the length of the line segment. There are two cases.
The third point is inside of that initial sphere. If so, then you have the smallest sphere.
The third point is outside of that initial sphere. Then the solution at Find Circum Center of Three point of Triangle [Not using Compass] will give you the center of the smallest sphere containing those 3 points.
If you need an arbitrary number of points, I'd do some sort of iterative approximation algorithm. Since you don't seem like you need that, I won't work out the details.

how to determine whether a point is above or below a polygon,not inside of the polygon?

I am taking Computer Graphics course.In 3D,I have a point and a polygon and I want to determine this point is located above or below my polygon.Thanks for your replies,in advance.
If above or below the plane on which the polygon is resting will do, you can compare the dot product of the point onto the plane normal and that of any point on the plane. Or look at the sign of the dot product between the normal and a vector from a point on the plane to the point, if you prefer.
To check whether it is actually 'above' or 'below' in the sense of being directly above or below (ie, not off to the side somewhere) then do a point in polygon by projecting the whole thing into 2d along the normal and then a distance along normal test.
It depends on your definition of above and below, let me first talk about the easy case:
If you think of above/below in terms of a global direction (typically the y-axis or z-axis), just compare the values on that axis.
Ok, now the more difficult interpretation: On which side of the polygon is the point.
Unless it is complanar you cannot decide it for the polygon at once. So if it is non-complanar you have to tesselate it into triangles and decide for each of them.
For a triangle you can decide whether a point is above or below it (in 3D), first calculate the cross product of 2 vectors that make up the sides of the triangle; this will define a direction (= the definition of "above" and "below"), this depends on the order in which you use those 2 vectors so be careful. Then calculate the dot-product of the new vector (which is called the perpendicular of that triangle) and the difference-vector of the point-to-test and the triangle-base.

How to determine ordering of 3D vertices

If I have 5 Vertices in 3D coordinate space how can I determined the ordering of those Vertices. i.e clockwise or anticlockwise.
If I elaborate more on this,
I have a 3D model which consists of set of polygons. Each polygon is collection of vertices and I want to calculate the norm of the polygon surface. To calculate the norm I have to consider the vertices in counter clockwise order . My question is given set of vertices how can I determine whether it is ordered in clockwise or counter clockwise?
This is for navigation mesh generation where I want to remove the polygons which cannot be walked by the agent. To do so my approach is to calculate the surface norm(perpendicular vector of the polygon) and remove the polygon based on the angle with 2D plane. To calculate the norm I should know in which order points are arranged. So for given set of points in polygon how can I determine the order of the arrangement of points.
Ex.
polygon1 consist of Vertex1 = [-21.847065 -2.492895 19.569759], Vertex2 [-22.279873 1.588395 16.017160], Vertex3 [-17.234818 7.132950 7.453146] these 3 points and how can I determine the order of them
As others have noted, your question isn't entirely clear. Is the for something like a 3D backface culling test? If so, you need a point to determine the winding direction relative to. Viewed from one side of the polygon the vertices will appear to wind clockwise. From the other side they'll appear to wind counter clockwise.
But suppose your polygon is convex and properly planar. Take any three consecutive vertices A, B, and C. Then you can find the surface normal vector using the cross product:
N = (B - A) x (C - A)
Taking the dot product of the normal with a vector from the given view point, V, to one of the vertices will give you a value whose sign indicates which way the vertices appear to wind when viewed from V:
w = N . (A - V)
Whether this is positive for clockwise and negative for anticlockwise or the opposite will depend on the handedness of your coordinate system.
Your question is too poorly defined to give a complete answer, but here's the skeleton of one.
The missing part (the meat if you will), is a function that takes any two coordinates and tells you which one is 'greater' than the other. Without a solid definition for this, you won't be able to make anything work.
The rest, the skeleton, is pretty simple. Sort your list of vectors using your comparison function. For five vectors, a simple bubble sort will be all you need, although if the number of vertices increases considerably you may want to look into a faster sorting algorithm (ie. Quicksort).
If your chosen language / libraries provide sorting for you, you've already got your skeleton.
EDIT
After re-reading your question, it also occurred to me that since these n vertices define a polygon, you can probably make the assumption that all of them lie on the same plane (if they don't, then good luck rendering that).
So, if you can map the vector coordinates to 2d positions on that plane, you can reduce your problem to ordering them clockwise or counterclockwise in a two dimensional space.
I think your confusion comes from the fact that methods for computing cross products are sometimes taught in terms of clockwiseness, with a check of the clockwiseness of 3 points A,B,C determining the sign of:
(B-A) X (C - A)
However a better definition actually determines this for you.
In general 5 arbitrary points in 3 dimensions can't be said to have a clockwise ordering but 3 can since 3 points always lie in a plane.

Resources