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

You are not logged in.

## #1 Re: Help Me ! » Change the direction of a vector by another vector » 2011-04-04 00:42:07

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?

## #2 Help Me ! » Change the direction of a vector by another vector » 2011-04-02 05:53:28

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!

## #3 Re: Help Me ! » points (x,y), in which directio are they connected? » 2011-02-15 00:41:43

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!

## #4 Re: Help Me ! » points (x,y), in which directio are they connected? » 2011-02-13 01:25:49

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?

## #5 Help Me ! » points (x,y), in which directio are they connected? » 2011-02-10 08:39:25

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!

## #6 Re: Help Me ! » spline formulas » 2010-05-28 20:42:18

It is a small change yet very noticable.

## #7 Re: Help Me ! » spline formulas » 2010-05-28 00:16:16

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.

## #8 Re: Help Me ! » spline formulas » 2010-05-27 09:53:20

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.

## #9 Help Me ! » spline formulas » 2010-05-27 02:54:16

safra
Replies: 7

Hi,

I currently use a  CatmullRom 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

## #10 Re: Help Me ! » splines » 2009-03-31 20:29:59

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

## #11 Re: Help Me ! » splines » 2009-03-31 00:24:02

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?

## #12 Help Me ! » splines » 2009-03-30 09:56:11

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

## #13 Re: Help Me ! » line intersection » 2009-03-24 10:06:32

Thanks a lot guys, I got it working!

## #14 Re: Help Me ! » line intersection » 2009-03-23 10:25:27

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.

## #15 Re: Help Me ! » line intersection » 2009-03-23 06:33:01

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 !=
?

## #16 Help Me ! » line intersection » 2009-03-22 07:10:47

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

## #17 Re: Help Me ! » Vector to angles » 2006-09-12 08:11:26

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?).

## #18 Re: Help Me ! » Vector to angles » 2006-09-12 03:23:07

luca-deltodesco, I belief you for the full 100%. It was just to say that I cannot get the rotation order by doing what you suggested as no matter what order I tried it resulted in the same end position. I hope I can find more about this.

## #19 Re: Help Me ! » Vector to angles » 2006-09-11 22:21:08

I did a test with 2 meshes. mesh1 by default rotated on all 3 axis in one call. Mesh 2 rotated by each axis individually at a time. The order does not influence the end rotation. Mesh 2 always ends up exactly like Mesh 1.

## #20 Re: Help Me ! » Vector to angles » 2006-09-11 10:11:48

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

## #21 Re: Help Me ! » Vector to angles » 2006-09-11 04:59:04

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?

## #22 Re: Help Me ! » Vector to angles » 2006-09-10 20:55:49

Urgh, is this complicated? Basically I just have a normalvector where the x,y,z, values needs to be transformed to degrees (I think).

## #23 Help Me ! » Vector to angles » 2006-09-10 00:44:05

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!

## #24 Re: Help Me ! » Move around circle » 2006-08-11 21:19:18

Thanks for offering your help! I did a search and found some good information that should get me going with this. If not then I will let you know.

## #25 Re: Help Me ! » Move around circle » 2006-08-10 08:11:30

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!