Discussion about math, puzzles, games and fun. Useful symbols: ÷ × ½ √ ∞ ≠ ≤ ≥ ≈ ⇒ ± ∈ Δ θ ∴ ∑ ∫ π -¹ ² ³ °

You are not logged in.

- Topics: Active | Unanswered

I guess I meant how to rotate an existing vector according another vector?

I have been reading about quaternions, cross products, eulerAngles etc, still confused on how to do this?

Anyone who knows how to do this?

**safra**- Replies: 2

Hi,

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.

Thanks!

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!

Thanks again!

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?

**safra**- Replies: 8

Hi,

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!

It is a small change yet very noticable.

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.

Hi bobbym,

Yes, that is the idea, recalculate the spline using the new control points. The x,z shape should stay the same as the new control point is located exactly on the existing spline curve.

**safra**- Replies: 7

Hi,

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!

Regards,

Raoul

Thanks luca-deltodesco! Found some nice code about all of this at http://actionsnippet.com/?p=1042.

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?

**safra**- Replies: 4

Hi,

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?

Thanks

Thanks a lot guys, I got it working!

gnitsuk, thanks for your reply, I missed it! I am not really into matrices and just don't have an idea how to put your solution into code.

luca-deltodesco , I will try your updated code tomorrow.

Many thanks luca-deltodesco. I read your reply this morning and did a quick test. It didn't work but I have to do more tests. I just wanted to say thanks a lot for your big post.

Just to be sure, I have never seen this operator ~=~

Is it like !=

?

**safra**- Replies: 9

Hi,

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:

Ax+By=C

but how can you get the intersection point out of 2 vectors like described above?

Raoul

@ 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?

**safra**- Replies: 12

Hi,

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!