I have a Vector A (xyz) and another vector B (xyz). Let's say A becomes a "child" of B and inherits the B direction as the origin. How can I get the new direction of A based on its old direction and the direction B is pointing at?
Sorry for the poor explanation, I don't know the right wording for this which also makes it hard to search for the solution. I have read about matrices etc. but no luck so far.
Many thanks Bob for all your efforts!
All points are in the first quadrant, but I belief there is still a issue with the first approach regarding detrmining whether and angle is for example +225 or - 135, correct?
Yor second solution contains a lot of Math specific terminology and syntax. I must admit, all that is a bit rusty over here : ). I have to go away for a couple of weeks, when I am back I will see if I can get this to work!
Hi guys, thanks for the replies!
@Bobbym, indeed it involves a large number of points all connected, the shape isn't necessarily circular. They can go up down, left right, left and so fort, but lines between points never cross! The points represent the outer vertices of a mesh. Meanwhile I found some info about this. One guy had a clever remark saying that in this case the direction is always either clockwise or ccw because of the nature of how the triangles are setup. But on testing this I found that this is not necessarily true although it seems there is a pattern. Not sure if I can rely on that as it involves processing of many meshes simulataneously I am looking for another way, a way that is for sure bullet proof.
@Bob Bundy, Not sure where O comes from, the origin, is this (0,0)? Also find it it complicated to figure out how to automatically determine whether the angle is positive or negative. I can see you define it as positive when the order of the points pPrevious, O, pNext is clockwise. But how to figure that out? And why is p4, O, p1, -260 and not +100?
I have a number of consecutive points (x,y) in an array, they are all connected like p1 with p2, p2 with p3, p3 with p4 etc. with the last vector connected with p1.
I have to find out whether the points are connected in clockwise direction or counterclockwise direction. Can anyone think of some clever way to find this out?
Thanks for replying bobbym!
Yes, it does pass through all control points. The formula I use calculates the curve between 2 control points by using 2 outer control points. So each curve between 2 control points is based on the position of 4 control points. That said, inserting a control point (even if exactly on the current spline shape) will lead to a different shape! Something I do not want to happen.
I currently use a CatmullRom type of spline formula in a 3D world to interpolate between control points. I had like to be able to insert control points exactly on the spline for more detail on the y-axis. I found that this results into a nasty bending on the x,z axis as well. Anyone knows of a spline formula that will allow me to do this which will keep the curve shape on the x,z axis the same? Or perhaps is there way to use the catmull-Rom formula for this by using a specific "tension" value?
Any help much appreciated!
Thanks John, I quickly looked at the examples and it seems like a good start. But after thinking more about it I am not sure if typical spline interpolation is what I need?
Please look at the example below. Connecting 3 points results in something like in figure 1 with spline interpolation. Connecting 4 points results in something like figure 2 below. This is not what I need. In my case I am adding points constantly and I do not want the tangent (this is what it is called if I am right?) of the last added point to change (C in figure 2) . The angle at point C should remain the same like in figure 3. The rotation at point D should probably depend on the angle between BC and BD and the distance between CD. Then while interpolation over a timespan I need to find the points on the curve between each 2 points.
Is this indeed a type of Spline interpolation or is there another way to do this?
I have a set of points in 3D space and want to interpolate through them smoothly over a specific timespan. I searched for spline interpolation code and found some info (http://en.wikipedia.org/wiki/Cubic_Hermite_spline) and also on this forum (http://www.mathisfunforum.com/viewtopic.php?id=4092) but can't get the grasps of it.
Anyone knows of a source with code examples?
I am coding something and need to know if the line between points AB and the line between points CD intersect. So I can get the direction of both lines by subtracting Vector B from A and D from C.
I remember from math classes a long while how to find x and y values of 2 lines when they are known like something like this:
but how can you get the intersection point out of 2 vectors like described above?
There is is still no 100% clear answer to this but all of us, including real DirectX experts online, think it is YXZ (Y > up, X > right, Z > forward) because all functions related to this have YawPitchRoll in it which basically stands for YXZ (not sure if this is the same in maths terminology?).
@ Dross, Yes, That's what I mean with normal vector and yes it is 3D where Y is up, x is right and Z is forward.
@ luca-deltodesco, I did a quick search for the rotation order but no luck so far. I will search further and post here if I find it. Is the solution different for each type of order or is there a basic approach and can I find out the correct order by trial and error?
Perhaps this is more complicated then I thought. The directx wrapper has a Mesh SetRotation function for all 3 axis. My Thoughts were, a normal vector points in a certain direction depending on the x,y and z values. So it should be possible to calculate the angles this vector makes with the x,y and z axis. As this is a landscape/mesh positioning issue my thoughts were also that horizontal rotation of the mesh (y-axis) is not related to the normal vector but depends on the direction the mesh should point at. So needed are the x and z rotation angles to align the mesh with the landscape at a specific position. Is this relevant information, or am I completely lost here? I don't know about the order of rotations, perhaps this is something I should experiment with when I have a basic idea of how to solve this issue?
I have another directx question. I have a normal vector (position on landscape). Now I want to align another mesh with the landscape using this normal vector. Does anyone know how I can get the rotation values in degrees (0..360) for all three axis based on the landscapes normal vector?
I used matrices before for this, unfortunatly this time I need another approach because matrices are not supported for this kind of mesh. I tried a lot with asin and acos but nothing worked. The only thing that seemed right was using:
xrot = ASin(LandVector.x);
But I couldn't get this working for the z-axis? I belief the Y -axis should just be 0 or the value I want it to point at, correct?
Any help would be much appreciated!
I am using pascal (delphi). I read many things about sin and cos. Some saying it is expensive while others did tests and found that it was indeed faster or at least something similar as using a lookup table. I think I should test this myself as I am already using quite a lot of sin and cos in my program.
Well if indeed this is what I should use then I should be able to get it working, thanks again!