Let's suppose:
1) XY plane is perpendicular to the surface of the street given by an area between the two green lines and a normal to this plane has the same "direction" as the yellow line,
2) XY has only three degrees of freedom - moving along X, Y, Z (Z is X x Y),
3) a limit for an X- along translation is when P1 is coincident to P2.
How does the θ change while translating by an [x,y,z] vector? How would it change if I added a rotation along any of the given axes and got rid of the point 3) (6 degrees of freedom)? Can you give me any hint where to look for an answer?
Hope everything is clear!
Related
I am programming a raycaster in JavaScript. I am having trouble finding or implementing an algorithm for the raycast. Currently I am trying out the cast in the following style.
Theres an grid with equal block width and height. My player has a position within the grid, a direction as an angle 0 - 360 degrees where hes looking at. In the first step I need to figure out the distace from my Player to the Green dot at the Grid Intersection. I know that the Green Point is at the Intersection therefore i can figure out the length of the red line. Theres an right angle at the intersection. When I ve calculated the distance or x and y position of the green dot I have to do a simular thing in the 2nd step. The distance of the orange line is known, the position of the green dot and the angle is known. Again the right angle is on the intersecting border line.
I am not even sure if its possible this way, but maybe you got any other idea how I should then work it out. Thank you very much.
(Apologies for formatting below; I'm tapping this out on a phone)
From trigonometry, cos(aplha) = (length of red line)/(length of hypotenuse).
Therefore: length of hypotenuse = (length of red line)/cos(alpha).
You'd use sin for a vertical intersection.
A word of caution though: if you think about what would happen when the player is looking directly at a wall, all the lengths should be the same so that it's a constant height on screen, but they'll actually be different because the diagonals are different. You need to multiply by cos of the relative angle between the player's direction and the casting direction (so, if you've a 60 degree field of view then 0 at the centre of the display, off to +30 at one end and down to -30 at the other).
Also don't fall into the common trap of thinking that the angles you cast at should be evenly spaced. Think again of a person looking directly at a wall and use atan to get the proper relative angles.
The parametric equations of the ray read
X = x + t cos α, Y = y + t sin α
with t>0.
Assuming a unit grid (but you can rescale), and the angle in the first quadrant, the first intersections with the grid are
X = ceiling(x) => t = (X - x) / cos α => Y = y + (X - x) . tan α
and
Y = ceiling(y) => t = (Y - y) / sin α => X = x + (Y - y) . cot α
The smallest of the two t will tell you which of the horizontal and vertical is met first.
The next intersections are with X = ceiling(x) + i, and Y = ceiling(y) + j, hence the Y increase in steps tan α and the X in steps cot α.
For the other quadrants, the ceiling's are replaced by floor's.
I have two axis linked together ; Axis A, and Axis B. Axis B is attached to the end of Axis A and so its point of origin can vary with the angle of Axis A . Attached to Axis B is a Circle whose Diameter is 10 (and can become smaller). I need to move the edge point of the circle to intersect a Super-Ellipse at each of 38 Cartesian points x,y. So the end point of my axis B - center of the circle should follow the same basic path as the 38 points of the super ellipse - radius of circle. Once I have these points - I will need to determine the position of Axis A x_2,y_2 and angle (or more appropriately just the distance from 0 degree angle to reach the required angle to position x_2,y_2. I then need to position Axis B with relation to Axis A in order to have Axis B X_3,Y_3 match the following of the Super-Ellipse where the center of the circle is supposed to be.
I have a drawing attached and a plot in Excel where I am off as you can see the bow tie is not what I should have. I have also included the points to the super ellipse along with some quick points on the graph. I am not a math major - I am willing to learn if you post the name of an equation - so far I have learned about carnot, parametric equation for circles and formulas for parabolas - but I am still having trouble.
Axis A Radius 13" image is 90 degree rotation
X_Sub1 , Y_Sub1
-6.5 , 5
Axis B Radius 9" image is 180 degree rotation
X_Sub2 , Y_Sub2
6.5 , 5
Circle Diameter 10"
Circle Radius 5"
Super Ellipse
# 12"width
# 8.75" Deep Vertex -8.75
Points Along the Super Ellipse.
0.0000, 0.0000
0.2188, -0.6250
0.2188, -1.2500
0.2433, -1.8750
0.3290, -2.5000
0.4753, -3.1073
0.6804, -3.7091
0.9424, -4.2990
1.2585, -4.8712
1.6255, -5.4197
2.0397, -5.9388
2.4967, -6.4233
2.9920, -6.8682
3.5203, -7.2889
4.0764, -7.7213
4.6544, -8.0500
5.2285, -8.3553
5.7525, -8.5000
6.2188, -8.5516
6.6851, -8.5000
7.1891, -8.3553
7.7832, -8.0500
8.3612, -7.7213
8.9173, -7.2889
9.4456, -6.8682
9.9409, -6.4233
10.3979,-5.9388
10.8121,-5.4197
11.1791,-4.8712
11.4952,-4.2990
11.7572,-3.7091
11.9623,-3.1073
12.1086,-2.5000
12.1943,-1.8750
12.2188,-1.2500
12.2188,-0.6250
12.4376, 0.0000
First, suppose we have 3 points along the super-ellipse, p0 = (2.4967, -6.4233), p1 = (2.9920, -6.8682), and p2 = (3.5203, -7.2889). Let's figure out how to position it to touch the point p1.
First of all at the point p1 the tangent line should be very close to parallel to the line from p0 to p2. So it should be parallel to p2 - p0 = (3.5203, -7.2889) - (2.4967, -6.4233) = (1.0236, -0.8656). But you want the disk to be perpendicular to this. We can construct a perpendicular to the vector (x, y) by (-y, x), which gives us (0.8656, 1.0236) as a direction. (There are two perpendiculars, looking at the diagram this is obviously the correct one.) This means that we want to put the end of axis B a distance of 5 in that direction. Which means it needs to be a distance of 5 in the direction (0.8656, 1.0236) from p1 = (2.9920, -6.8682). So it should be at the position (2.9920, -6.8682) + 5 * (0.8656, 1.0236) / sqrt(0.8656^2 + 1.0236^2) = (6.22057, -3.050307).
Now that we know where the end of axis B is, assuming we know where the start of axis A is (you didn't specify that), we can use the law of cosines (see http://mathworld.wolfram.com/LawofCosines.html) to figure out the cos of the angles that you want. Now you can use the arccosine function to figure out the angles in question.
This procedure can be followed for every point. Figure out what you think it should be tangent to, find the orthogonal, find where you want the end of B to be, then you have a triangle that you can use the cosine law on.
So I have 3 points in a 3D space with a curve passing through the points. I have found the tangent of the point in the middle by averaging the two points either side of it, but I want to find the Normal at the point in the middle. How would I do this without knowing the equation of the line?
`P(1) = (0,1,0)
P(2) = (2,2,2)
p(3) = (4,4,4)
Tangent at P(2) = (4,3,4)`
Thanks!
A = P2 - P1 ... vector between 2 points on the curve (one is the middle point .. P2)
normal = A x tangent
but as MBo pointed out there are infinite number of normals (all are perpendicular to the curve lying on the same plane)
above equation gives one perpendicular to curve and to that A vector
I'm trying to place my hero's feet on a ground made up of line segments.
If I know the X,Y of points A, B, and C and the X of Hero, how do I find the Y of Hero so that his feet touch the ground (assume X is the middle of the Hero and Y is along the bottom)? And do I have to do anything differently if he's standing exactly over a point?
Thanks.
If A and B are two points in a coordinate plane with points (xA, yA) and (xB, yB) respectively - then the slope of the line between them is simple geometry - delta y/delta x, or (yB-yA)/(xB-xA). The general form of the line can be given as y = yA+(yB-yA)/(xB-xA)*(x-xA)
I'm using Electro in Lua for some 3D simulations, and I'm running in to something of a mathematical/algorithmic/physics snag.
I'm trying to figure out how I would find the "spin" of a sphere of a sphere that is spinning on some axis. By "spin" I mean a vector along the axis that the sphere is spinning on with a magnitude relative to the speed at which it is spinning. The reason I need this information is to be able to slow down the spin of the sphere by applying reverse torque to the sphere until it stops spinning.
The only information I have access to is the X, Y, and Z unit vectors relative to the sphere. That is, each frame, I can call three different functions, each of which returns a unit vector pointing in the direction of the sphere model's local X, Y and Z axes, respectively. I can keep track of how each of these change by essentially keeping the "previous" value of each vector and comparing it to the "new" value each frame. The question, then, is how would I use this information to determine the sphere's spin? I'm stumped.
Any help would be great. Thanks!
My first answer was wrong. This is my edited answer.
Your unit vectors X,Y,Z can be put together to form a 3x3 matrix:
A = [[x1 y1 z1],
[x2 y2 z2],
[x3 y3 z3]]
Since X,Y,Z change with time, A also changes with time.
A is a rotation matrix!
After all, if you let i=(1,0,0) be the unit vector along the x-axis, then
A i = X so A rotates i into X. Similarly, it rotates the y-axis into Y and the
z-axis into Z.
A is called the direction cosine matrix (DCM).
So using the DCM to Euler axis formula
Compute
theta = arccos((A_11 + A_22 + A_33 - 1)/2)
theta is the Euler angle of rotation.
The magnitude of the angular velocity, |w|, equals
w = d(theta)/dt ~= (theta(t+dt)-theta(t)) / dt
The axis of rotation is given by e = (e1,e2,e3) where
e1 = (A_32 - A_23)/(2 sin(theta))
e2 = (A_13 - A_31)/(2 sin(theta))
e3 = (A_21 - A_12)/(2 sin(theta))
I applaud ~unutbu's, answer, but I think there's a simpler approach that will suffice for this problem.
Take the X unit vector at three successive frames, and compare them to get two deltas:
deltaX1 = X2 - X1
deltaX2 = X3 - X2
(These are vector equations. X1 is a vector, the X vector at time 1, not a number.)
Now take the cross-product of the deltas and you'll get a vector in the direction of the rotation vector.
Now for the magnitude. The angle between the two deltas is the angle swept out in one time interval, so use the dot product:
dx1 = deltaX1/|deltaX1|
dx2 = deltax2/|deltaX2|
costheta = dx1.dx2
theta = acos(costheta)
w = theta/dt
For the sake of precision you should choose the unit vector (X, Y or Z) that changes the most.