Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
In my case I have a starting coordinate x,y,z, an orientation in Quaternion and I know the moved distance.
Basically I would like to know the x',y',z' after applying the transformation and the forward movement. So I am trying to move a point in 3D using quaternion. I guess it should be just a simple calculation but for some reason I cannot find the solution that easily.
In previously I converted the Quaternion to Euler angles and used them to calculate the x',y',z'. Unfortunately because of the Gimbal lock this solution is not suitable for me anymore.
I have found a few example for example this one in python and here's an other in C#, but I still did not get the formula of them as they are discussing the rotation instead of the movement it self, the C# example just changes the middle point of the cube and then it redraws it with the rotation.
Why reinvent the wheel ? This kind of operation is best handled via matrixes - and C# has even support for it.
// PresentationCore.dll
using System.Windows.Media.Media3D;
Matrix3D matrix = Matrix3D.Identity;
matrix.Translate(new Vector3D(x, y, z));
matrix.Rotate(quaterion);
var newPoint = matrix.Transform(point);
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 3 years ago.
Improve this question
I've got an issue in my VR project. I'm trying to move one object based on rotation of another one and first one should move only in kind of borders. I'm using a raycast to detect and control these objects. Both should go in x direction.
1 - Object that I rotate
2 - Object that should move
Any tips? Thanks in advance!
Well this looks like a lathe so I asume that you want to move the tool post over one axis when rotating the wheel.
You want to "link" them, so what I would do is rotate the wheel using a method that also moves the tool post.
Try this:
public float ratio = 1.0f;
public GameObject wheel;
public GameObject tool;
public void RotateWheel(float amount)
{
wheel.transform.Rotate(Vector3.forward * amount);
tool.transform.Translate(Vector3.left * amount * ratio);
}
Note the following:
Amount is passed as degrees.
Ratio is the ratio between wheel
rotation and tool translation. At 1, for each degree, the tool moves
1 unit. Adjust it at your will. I assumed the orientation of your
moving parts based on the model. Try changing the vector directions if they do not work as expected.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 4 years ago.
Improve this question
I'm trying to build a 2D physics engine (rigid body dynamics simulation) in C#. So far I have simulated boxes (squares) of different sizes which are fixed in position but can rotate around their centroids (centre of mass) when a force is applied to them. This is the Box.ApplyForce() method that is called when a force is applied:
public void ApplyForce(double x, double y, Vector force)
{
//angular acceleration = torque(angular force) / moment of inertia
Force tempForce = new Force(x, y, force.X, force.Y);
forceList.Add(tempForce);
Vector displacement = new Vector(x, y);
double torque = displacement.X * tempForce.yForce - displacement.Y * tempForce.xForce;
double momentOfInertia = (mass*(size*size*2))/12;
angularAcceleration += torque / momentOfInertia;
}
Now this seems to be working correctly so far, but I now need to include translational acceleration in my simulation so my question is: what happens when you apply force to the edge (or any non-centre-of-mass point) of the object? Will the translational acceleration be the same as if it were applied to the centre of mass?
Are these simulated squares on a flat surface when simulating translational motion? Can they rotate when the force is applied, and also move translational?
If the box is on a flat surface it cannot rotate when you are simulating translation acceleration it does not matter where the force is applied. It just matters the angle at which the force is applied, or the component of the force vector in the direction of the translational motion. The component of the vector perpendicular to surface will affect the magnitude of the normal force, which will affect the frictional force if that is something you are taking into consideration.
If the box is not on a surface and just floating in space when the force is applied the answer gets a bit more complicated. Maybe clarify what you are simulating a bit more.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
I want to create a procedural mesh like you can see in the following picture:
Unfortunately I have no idea how to do that. Can anyone of you help me out?
I think I know how to create the mesh of the tube, but I do not know how to create those circles.
The following is a rough overview of how to edit the vertices of a mesh, but for more details this link might help you.
List<Vector3> vertices = new List<Vector3>();
List<int> triangles = new List<int>();
GenerateMesh(vertices, triangles);
Mesh mesh = gameObject.GetComponent<MeshFilter>().mesh;
mesh.vertices = vertices.ToArray();
mesh.triangles = triangles.ToArray();
In terms of actually generating your mesh, I would suggest generating N points in a circle on a plane, this is your start point. Then repeatedly move the plane forward slightly, rotate it, and generate more points. Each time connect the points to the previous set of points generated to make your triangles.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
I want to make the player move by a specific amount (1 tile/unit in this case) and then stop him. Just like in this video:
http://www.youtube.com/watch?v=DotOAbNngc4
By pressing a key the player should move smoothly to the next tile, than stops and so on.
How can I archieve this? (in C#)
You could take a look at GridMove which is from UnifyWiki.
You would probably get more of a response if you posted this question to answers.unity3d.com or forum.unity3d.com as these forums are specifically target towards Unity3d.
Here's what I would do: you give your player class a target field, e.g. a 2d vector. This will either contain the current position of the player (when initializing or when the target has been reached) or the target that you want to move the player to.
Now in your update you do this:
if target equals your current position then check user input for movement.
if user requests movement set target to position adjacent to current position.
else slowly move player towards target.
You may want to create a field for the current position of the player besides the normal position in GameObject. You could then update GameObject.position in the update-cylce by a small delta until the positions of GameObject.position and target have the (roughly! use epsilon when comparing) same value.
Some hints
Vector2.MoveTowards can help you
To check if the target and position are "close enough" you could subtract one from the other and look at the resulting vector's magnitude.
Beware of overshooting when you move towards the target. If your movement distance is more then or equal to the distance between position and target, just set the position to the target.
Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
I have two line segments with points
Line1 = (x1,y1) , ( x2,y2) --- smaller
Line2 = (x3,y3) , (x4,y4) --- bigger
How can I make the Line1(smaller) to rotate and make it parallel to Line2(Bigger)
using either
1) (x1,y1) as fixed point of rotation or
2) (x2,y2) as fixed point of rotation or
3) center point as fixed point of rotation
I am using C#.NET.
And Aforge.NET Library.
Thanks
All operations described below can be expressed as affine transformation matrices.
Move desired rotation center into the origin.
Compute either angle of rotation or directly the rotation matrix. See below.
Apply that rotation, as a rotation around the origin.
Apply the reverse translation to move the rotation center back to its original position.
You can multiply these three matrices to obtain a single matrix for the whole operation. You can even do so with pen and paper, and hardcode the result into your application.
As to how you compute the rotation matrix: The dot product of the two vectors spanning the lines, divided by the length of these vectors, is cos(φ), i.e. the cosine of the angle between them. The sine is ±sqrt(1-cos(φ)²). You only need these two numbers in the rotation matrix, so no need to actually compute angles in terms of performance. Getting the sign right might be tricky, though, so in terms of easy programming you might be better of with two calls to atan2, a difference, and subsequent calls to sin and cos.