How to find the x and y coordinates of a circle given a plot, the original rotation, the new rotation, the origin and radius? - math

The easiest way I know how to explain this is with a picture so here it is:
http://pbrd.co/19RxqqV
For simplicity the origin is 0,0 and the angles are easy to work with but they could potentially be anything. The only things I really consistently know for this type of problem is the rotation of the circle, the origin and the radius and then of course the new degree/rotation of the circle.
This question, I think is similar but not really the exact same thing:
Finding the coordinates on the edge of a circle
Thanks! I hope my question is clear enough.

The coordinates of a point with angle a with respect to x-axis on a circle of radius r are:
x = r*cos(a*Pi/180), y = r*sin(a*Pi/180)
In your case a=45+135

Related

Find point in 3D plane

I have four points in a 3D space, example:
(0,0,1)
(1,0,1)
(1,0,2)
(0,0,2)
Then I have a 2D position on that square plane:
x = 0.5
y = 0.5
I need to find out the 3D space point of that position in the plane. In this example it's easy: (0.5,0,1.5), because Y is zero. But imagine that Y was not zero (and not all the same), that the plane is leaning in some direction. How would I calculate the point in that case?
I imagine this should be a pretty easy thing to solve, but I can't figure it out. Please answer in programming terms and not in straight math terms, if possible.
Update with image: The gray plane (made out of two triangles) are the real one actually existing. I create a non-existing plane on top of this, the ABCD corners are exactly the same, however it doesn't slope. What I need to do is project a pixel (blue one in example) from the non-existing plane to the existing plane. It will be in the exact same location, except that it has gained a Y value from the sloping plane.
(couldn't actually make the image appear because i need 10 reputation to show it, wtf?)
What I've been able to work out so far on my own is which one of the two triangles to use in the gray plane and the normal of triangle. I basically just need to figure out how I can project the pixel.
Figured it out mostly thanks to http://gamedeveloperjourney.blogspot.com/2009/04/point-plane-collision-detection.html
Made me realize I had to verify the normal a bit closer, turns out my plane's grid was being rendered a little different than the actual coordinates for the verticles. No wonder this was so hard to get right! The pixel was projected correctly but rendered incorrectly.

Trigonometry: 3D rotation around center point

Yeah, yeah, I checked out the suggested questions/answers that were given to me but most involved quaternions, or had symbols in them that I don't even HAVE on my keyboard.
I failed at high school trig, and while I understand the basic concepts of sin and cos in 2D space, I'm at a loss when throwing in a third plane to deal with.
Basically, I have these things: centerpoint, distance, and angles for each of the three axes. Given that information, I want to calculate the point that is -distance- away from the center point, at the specified angles.
I'm not sure I'm explaining this correctly. My intent is to get what amounts to electrons orbiting around a nucleus, if anyone happens to know how to do that. I am working with Java, JRE 6, if there are any utility classes in there that can help.
I don't want just an answer, but also the how and why of the answer. If I'm going to learn something, i want to learn ABOUT it as well. I am not afraid to take a lesson in trigonometry, or how quaternions work, etc. I'm not looking for an entire course on the answer, but at least some basic understanding would be cool.
If you did this in 2D, you would have a point on a plane with certain x and y coordinates. The distance from the origin would be sqrt(x^2+y^2), and the angle atan(y/2).
If you were given angle phi and distance r you would compute x= r*cos(phi); y=r*sin(phi);
To do this in three dimensions you need two angles - angle in XY plane and angle relative to Z axis. Calling these phi and theta, you compute coordinates as
X = r*cos(phi)*sin(theta);
Y = r*sin(phi)*sin(theta);
Z = r*cos(theta);
When I have a chance I will make a sketch to show how that works.

Camera rotation with a quaternion

I am having a problem with the maths of camera rotation, well more like I lack knowledge on this subject and can't find anything about it on the internet (read, most likely don't know the correct search keywords)
Anyway, this is what I am attempting to do (pseudo code):
RotateCamera(angle,axis){
Quaternion rotation = cam.getRotation();
Quaternion rot = new Quaternion();
rot.fromAngleNormalAxis(angle, axis);
rotation.multLocal(rot);
cam.setRotation(rotation);
}
update(float value){ // just to show what input I use the RotateCamera method for the directions
RotateCamera(value,Vector3f(0,1,0)) // left
RotateCamera(-value,Vector3f(0,1,0)) // right
RotateCamera(value,Vector3f(1,0,0)) // up
RotateCamera(-value,Vector3f(1,0,0)) // down
}
Now this works quite well but sometimes the cam will roll instead of only yaw/pitch. What is the correct way of doing this?
With just the bit of code given, it's hard to say for sure. But it looks like you've hard coded the axes of rotation into your update method. The thing about rotations (whether represented by quaternions or matrices) is that their multiplication isn't "commutative" meaning doing the same two rotations but in opposite orders does not give the same result.
It looks like you're assuming the camera is facing in the (0,0,1) direction, let's call it the z axis, with the y axis (0,1,0) coming out of the top of your head. As long as this assumption holds, you're axis of rotation for looking up, down, left and right will be (1,0,0), (1,0,0), (0,1,0) and (0,1,0) as they seem to be in your code snippet. But say you've just rotated 90 degrees to the left. This sends the camera's view from the (0,0,1) direction to the (1,0,0) direction. Now say you make an "up" rotation, which was coded to be around the (1,0,0) axis. This is a rotation around the same axis in which you're looking, and the effect will be a roll.
Does this address the issue? If so, you should code your axes of rotation w.r.t. the current direction the camera is facing.

Moving a Sphere so its Z-Axis faces a direction

Firstly - Z is Up in this problem.
Context: Top down 2D Game using 3D objects.
The player and all enemies are Spheres that can move in any direction on a 2D Plane (XY). They rotate as you would expect when they move. Their velocity is a 3D vector in world space and this is how I influence them. They aren't allowed to rotate on the spot.
I need to find a formula to determine the direction one of these spheres should move in order to get their Z-Axis (or any axis really) pointing a specified direction in world space.
Some examples may be in order:
X
|
Z--Y
This one is simple: The Spheres local axes matches the world so if I want the Spheres Z-Axis to point along 1,0,0 then I can move the sphere along 1,0,0.
The one that gives me trouble is this:
X
|
Y--Z
Now I know that to get the Z-Axis to point along 1,0,0 in world space I have to tell the sphere to move along 1,1,0 but I don't know/understand WHY that is the case.
I've been programming for ten years but I absolutely suck at vector maths so assume I'm an idiot when trying to explain :)
All right, I think I see what you mean.
Take a ball-- you must have one lying around. Mark a spot on it to indicate an axis of interest. Now pick a direction in which you want the axis to point. The trick is to rotate the ball in place to bring the axis to the right direction-- we'll get to the rolling in a minute.
The obvious way is to move "directly", and if you do this a few times you'll notice that the axis around which you are rotating the ball is perpendicular to the axis you're trying to move. It's as if the spot is on the equator and you're rotating around the North-South axis. Every time you pick a new direction, that direction and your marked axis determine the new equator. Also notice (this may be tricky) that you can draw a great circle (that's a circle that goes right around the sphere and divides it into equal halves) that goes between the mark and the destination, so that they're on opposite hemispheres, like mirror images. The poles are always on that circle.
Now suppose you're not free to choose the poles like that. You have a mark, you have a desired direction, so you have the great circle, and the north pole will be somewhere on the circle, but it could be anywhere. Imagine that someone else gets to choose it. The mark will still rotate to the destination, but they won't be on the equator any more, they'll be at some other latitude.
Now put the ball on the floor and roll it -- don't worry about the mark for now. Notice that it rotates around a horizontal axis, the poles, and touches the floor along a circle, the equator (which is now vertical). The poles must be somewhere on the "waist" of the sphere, halfway up from the floor (don't call it the equator). If you pick the poles on that circle, you choose the direction of rolling.
Now look at the marks, and draw the great circle that divides them. The poles must be on that circle. Look where that circle crosses the "waist"; that's where your poles must be.
Tell me if this makes sense, and we can put in the math.

Axis Rotation Question

By using left hand rule, I rotate one object left and right using y axis, and rotate up/down using x axis.
After first object is rotated to the right, the up/down rotation should be using z axis.
However, when I try to rotate using z axis, after the first rotation, it has the same effect when I rotate using y axis.
Anyone has any ideas?
Thanks
The proper order of rotations in order to keep everything straight is roll, pitch, yaw. That is, rotation around the X axis, rotation around the Y axis, rotation around the Z axis.
Not sure what your question is, but if you're asking why this happens, the answer is that rotations are not commutative. That is, a rotation of theta about axis A followed by a rotation of phi around axis B is not the same as rotation of phi around axis B followed by a rotation of theta around axis A.
If you're asking why a sequence of operations that seems okay when you visualise it fails to work in code, be sure you're using a right-handed coordinate system. Also, it might be helpful to work through your various rotation matrices for the x, y and z axes using the unit vector (1,0,0) - in fact, if you do it on paper you'll get a better intuition for what's happening.
Thanks for all the answers:
Sorry I didn't state the problem clearly.
That's the typical gimbal lock problem.
and my solution is to use quaternion rotation

Resources