I have a triangle in 3D space defined by its 3 vertices, p0, p1, and p2.
I wish to calculate a plane in this 3D space which lies along both p0 and p1 and faces a third point, p2.
This plane is to be defined by a position and normalised direction/
In addition to lying along p0 and p1, and facing p2, the plane should also be perpendicular to the plane created by p0, p1, and p2
I've struggled with this for quite a while and any help anyone can offer is greatly appreciated.
Your question is ill-posed. For any plane that lies on p0 and p1 there will be some point on that plane that "faces" point p2. So all that's left to compute is some plane along p0 and p1.
normal = normalize(cross(p1-p0, pX-p0)) //pX is anything except p1
planePoint = p0
EDIT: see comments
here is an example of my comment explanation
octave:14> p0
p0 =
0 0 0
octave:15> p1
p1 =
0 0 5
octave:16> p2
p2 =
5 0 0
octave:17> cross(p1-p0, cross(p1-p0,p2-p0))
ans =
-125 0 0
You'll notice that the sign is wrong, play with the order of parameters in the cross product to get it facing the right way. Also don't forget to normalize...but it wont affect the direction. Also check to make sure the norm after each cross product isn't near 0, otherwise there is no unique answer.. (triangle forms a line)
Unless I'm misunderstanding what you're asking, a vector from the line to p2 will be the normal to the plane you're trying to define. Basically, you construct a line at right angles to the line p0-p1, running through p2.
Related
I'm sure this is basic trigonometry, and I bet I covered at school many years ago, but I struggle knowing what function to apply to a real world situation. Anyway, rather than try and explain what I need help with, I've drawn a little diagram:
I know p1, p2, r1 and r2 but I can't remember (or know how to search for) how to work out what p3 and p4 are.
The basic application of this setup is I have 2 circles (red and blue) and I need them constantly connected as I drag them around the canvas. The pink link will connect them via their centre points but I don't want the line to penetrate the circle's circumferences.
Hope that makes sense? Thanks in advance.
this is simple vector math (no trigonometry needed)
create unit vector v with P1 to P2 direction
That is easy in vector form:
v=P2-P1; v/=|v|
And when put into 2D:
v.x=P2.x-P1.x;
v.y=P2.y-P1.y;
l=sqrt((v.x*v.x)+(v.y*v.y))
v.x/=l;
v.y/=l;
Now just translate from P1,P2by r1,r2
Vector form:
P3=P1+r1*v
P4=P2-r2*v
In 2D:
P3.x=P1.x+r1*v.x;
P3.y=P1.y+r1*v.y;
P4.x=P2.x-r2*v.x;
P4.y=P2.y-r2*v.y;
You have to solve the following equation system:
For p3 -->
(X-p1x)/(p1x-p2x)=(Y-p1y)/(p1y-p2y)
(X-p1x)^2 + (Y-p1y)^2 = r1^2
The same for p4 just change r1 for r2 and p1 for p4 in the second equation.
The first equation is the equation of a line given 2 points.
And the second equation is the equation of a circle given a center point and a radius.
The resulting X, Y values will be the values of p3, and then p4.
Let d be the distance between p1(x1, y1) and p2(x2,y2)
Thus
d = sqrt((x1-x2)^2 + (y1-y2)^2)
Now point p3(x3, y3) divides the line between p1 and p2 in the ratio of r1:(d-r1)
Thus
x3 = (r1*x2 + (d-r1)*x1)/d and
y3 = (r1*y2 + (d-r1)*y1)/d
Similarly for p4(x4, y4)
x4 = (r2*x1 + (d-r2)*x2)/d and
y4 = (r2*y1 + (d-r2)*y2)/d
What I am going to say is a little long. I will let you write your own code, however, of course will not help with that.
You know points P1, P2, and radius R1 and R2. Say suppose points P1 and P2 have coordinates (x1,y1) and (x2,y2) respectively.
The line connecting P1 and P2 is a straight line and hence you can calculate the slope of the line using the formula m=(y2-y1)/(x2-x1). Since you know the slope and know two coordinates, you can calculate the intercept c and construct a formula of the form y=mx+c.
Once the line formula is there, you can apply values for x and calculate y for point P3, lets say x3 and y3 since you have the radius R1. Similarly, calculate the coordinates for P4.
I have a plane with 3D coordinates of vertices in world coordinate system and also plane equation.
Coordinates
x y z
19.1320421 72.9177745 0 P1
19.1320426 72.9178202 0 P2
19.1320426 72.9178202 12.04 P3
19.1320421 72.9177745 12.04 P4
Plane eqn:
-0.999945876x+0.010404061y+0z-18.37241258 =0
Point:19.13208745 72.91761882 2.35762E-06
Can anyone describe or provide a link for how to find a point lies within or not in the plane that will help me understand and implement them?
If you plug in the values into the equation, then if the equality holds, the point lies in the plane. This means all you have to do is plug in x, y and z into the equation and check if it is equal to 0.
It's important to consider that you are using decimals here, so to make sure a rounding error does not throw you off you can simply check if its within a threshold.
A plane equation is the equation that will give a 0 for any points inside that plane. You already have the plane equation, so all you need to do is to enter the new x, y, z in the equation. If you get 0 then the point is in that plane.
Substituting the coordinates in the plane equation you should get zero if the point lies within the plane.
I have a problem (and a solution too). What I want to know is how to arrive at "that" solution. "That" solution is perfect and working fine for all possible combinations.
Assume that you have 3 points in the XY coordinate system: P1(x1, y1), P2(x2, y2) and P3(x3, y3).
Now, join the point P2 with P3. It will result in "ray" originating from point P2 and passing through point P3. I used word ray because I want it in only one direction, i.e. from P2 to P3.
Now, with respect to point P1, is the ray P2 --> P3 in a clockwise or counterclockwise direction?
Solution is:
use following formulae to find value of z1:
z1 = (x3 - x1)(y2 - y1) - (y3 - y1)(x2 - x1)
If z1 is positive, P2 --> P3 is clockwise. If z1 is negative, P2 --> P3 is counterclockwise. And if it is 0 the points are on the same imaginary line extending from P1.
Can someone please help me how to arrive at this solution?
The formula you've written is very similar to the formula of cross product of two vectors. As the direction of the cross product is dependent on the CW/CCW configuration, you can easily use it for your problem.
You can construct two rays P1->P2 and P1->P3. Then you can take their cross product. If the component of the product along Z-axis is positive, then P2 and P3 is in counterclockwise order, and vice versa.
If you try to do that, the result, which would be the coefficient of k (unit vector along Z-axis) in the cross product, will be precisely the same as the answer you mentioned.
I am not sure this works. I tried it, but it keeps giving me the same answer for both.
Try these coordinates:
Start point 0, 90, 0
Center point 0, 0, 0
End point 90, 0, 0
.....
directional vector 1, 0, 0
inverse directional vector -1, 0, 0
I am working on a track editor and have found myself in a situation where I need to define two touching circles. Ideally I would like to know the centre point, and radius of these circles.
The information I have is a point on the circumference of each of the circles, and the tangent to the circle at that point.
On my own I have figured out that if I know the tangents at those points I know the lines on which the centre points must lie.
C1 is the centre of the first circle I am looking for
P1 is a point on the circumference of the circle at which I know the tangent
A is the normal to the tangent that I know at P1
C2 is the centre of the second circle I am looking for
P2 is a point on the circumference of the circle at which I know the tangent
B is the normal to the tangent that I know at P2
C1 = P1 - t1 * A
C2 = P2 - t2 * B
I also know that the distance between the two centres will be equal to the sum of the distance of the centres from the points on the circumference.
|C1 - P1| + |C2 - P2| = |C1 - C2|
I also want abs( |t1*A| - |t2*B| ) to be kept to a minimum.
If you have only the tangent vectors and the point, there's not enough information. You need at least 2 more points, one more for each circle, otherwise t1 and t2 can be any real. (By the way, A = -B)
Disregard, I assumed that circles are not overlapping. Either way, we cannot know how large they are (and hence where the center points are) without knowing more information.
The problem is straight forward:
1) We have a photon traveling from Point 1 (x,y,z) to Point 2 (x,y,z), both of which could be located anywhere in 3D space.
2) We have a polygon that is both rotated randomly on the x-axis and/or y-axis and also located anywhere in 3D space.
3) We want to find: a) if the photon will collide with the polygon at all and b) if it does where will that be (x,y,z)?
An image of the problem: http://dl.dropbox.com/u/3150177/Programming/3D/Math/Photon%20Path/Photon%20Path.png
The aim of this is to calculate how the photon's path should be altered from an interaction(s) with the polygon(s).
I am reading up on this subject now but I was wondering if anyone could give me a head start. Thanks in advance.
Sounds like you are looking for a ray/polygon intersection test.
I can't remember the details but I imagine you split it into two parts. First you find the point on the polygon's plane that the ray intersects at. This can be got from a simple ray/plane intersection test. Secondly use a co-ordinate system on the polygon's plane to test whether the intersection point lies within the polygon. This can be got from a point-in-polygon test.
General overview:
1) Segment-Plane Intersection: Determine if the line segment connecting points 1 and 2 intersects the plane containing the polygon. If it doesn't, then it will never intersect the polygon, and you're done.
2) Find Point of Intersection: Determine the point at which the line segment and plane intersect. This will provide the information you want in 3-b in your question. Call this point Q
3) Determine if Q is interior to the polygon: One method of determining this is here, but a well crafted Google search will likely result in others. You can optimize for different types of polygons you expect (i.e. convex) or if the plane containing the polygon is axially aligned (i.e. one of the axes for your coordinate system is normal to the plane containing the polygon).
Assumption: All of the polygon's points are co-planar.
You're doing ray tracing. Most efficient is to break the polygon into triangles and use the Moeller ray-triangle test. Or perhaps the Wald test. There are also variants that use extra stored data beyond just the vertex information which can be even faster if you're doing multiple rays against the same triangle. Google provides so many results, I haven't selected a "best" one to put here.
The photon is traveling with vector v = p2 - p1 starting at p1, creating this line:
p1 + v * a
To find out if the photon collides with the polygon you have to find a value for a for:
p1 + v * a = polygon
For example:
p1 is (15, 4, 5)
p2 is (10, 1, 3)
and polygon is a 10x10 square: (-5...5, -5...5, 0)
v = p2 - p1 = (-5, -3, -2)
p1 + v * a = pol makes:
p1.x + v.x * a = pol.x
p1.y + v.y * a = pol.y
p1.z + v.z * a = pol.z
a = (pol.z - p1.z) / v.z = (0 - 15) / -2 = 7.5
pol.x = p1.x + v.x * a = 15 + -5 * 7.5 = -22.5
pol.y = p1.y + v.y * a = 10 + -3 * 7.5 = -12.5
The -22.5 is not between -5 and 5 and -12.5 is not between -5 and 5, so the photon does not collide with the polygon.
It's been a while since I've done this so I may have made some mistakes. I used the fact that pol.z = 0 to calculate a. You may have to rotate the polygon to line up with one axis, as long as you rotate p1 around the polygon's center as well.
Ray / triangle intersections are well understood and quite easy. The rotations are harder, though.
Perhaps you could transform the triangle's vertices using a rotation matrix and then use a simple ray / triangle intersection?