# Projecting a Curve along a Vector

This topic is 4668 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I'm currently writing a procedural walking system, where the path of each 'step' is governed by a target point which represents the ideal position of the foot, with inverse kinematics configuring the rest of the bones in the leg as the afformentioned foot traces the path of the target. If you look at the diagram below, the top shows the path of the target along a flat surface, where (a) is the start point, (b) is the end point and the height and distance of the 'step' being (h) and (d) respectively. My code currently looks like this:

Actor::takeTestStep()
{
float stepResolution = 150.0;     //amount of frames in the curve
float stepLength = 30.0;          //length of step
float stepHeight = 30.0;          //height of step

float prev_x = tween.x;
float prev_y = tween.y;

Vector3 forward = V2CV(Brain[0].GetForward());	//get forward vector of creature

tween = bezier_stride.evaluatePoint(stride_frame / stepResolution);

sph_pathPosition.mSphereNode->translate((tween.x - prev_x) * stepLength * forward.x, (tween.y - prev_y) * stepHeight * (1-forward.y), (tween.x - prev_x) * stepLength * forward.z);       //translate target sphere

if(stride_frame < stepResolution)
stride_frame++;
}


Which is fine, as long as the creature is moving across a flat surface. The algorithm simply projects a curve along the forward vector of the creature, with height stepHeight and distance stepLength. The problem is that this doesn't work when the creature's up vector isn't parallel to the ground's normal vector i.e the creature isn't on a flat surface. What I want to happen is similar to the second diagram - the curve remains the same, just rotated. What currently happens (due to the 2D nature of the algorithm) is that the curve gets distorted. Can I extend this algorithm so that the curve is always the same, just rotated - or am I going about this in the wrong way?

##### Share on other sites
hi. could you be more specific about how your curve is distorting? Maybe a new picture or something? I cannot try to tell you what the problem is if i don't see the wrong result.

##### Share on other sites
I haven't got access to my code at the moment, so I can't draw a corresponding diagram of the distortion. I'll try and explain it:

tween = bezier_stride.evaluatePoint(stride_frame / stepResolution);

The bezier evaluator returns the (0,1) x and y component of a pre-defined curve based on the current frame / number of frames. So if the pre-defined curve is similar to the first diagram, you'd get:

-------------
bezier_stride.evaluatePoint(1 / 150) = 0,0 (i.e the start of the curve)

and

bezier_stride.evaluatePoint(150 / 150) = 0,1 (i.e the end of the curve)

So plotted across all values, you get a 2D curve.
-------------

So we have code that describes the stride path of the creature's feet. What I want to do is combine this curve with the creature's forward vector, so that when it takes a step its along its current trajectory. For flat surfaces, this works fine - the Y component of the forward vector is always 1, whilst X and Z describe the direction across the plane in which the path will occur.

However, when I introduce a non-flat surface (rolling hills for example), the Y component of the forward vector is not 1. For example, lets say the forward vector is

Vector3(0,0.5,0)

So in other words the creature is on a slope.

If we look at the corresponding equation I currently use, it simply doesn't work. Something is missing, or its just inadequate.

mSphereNode->translate((tween.x - prev_x) * stepLength * forward.x, (tween.y - prev_y) * stepHeight * (forward.y), (tween.x - prev_x) * stepLength * forward.z); //translate target sphere

So whilst I want to get the result I see in the second diagram, its not going to happen I don't think by using this method.

##### Share on other sites
Quote:
 Original post by SFAHowever, when I introduce a non-flat surface (rolling hills for example), the Y component of the forward vector is not 1. For example, lets say the forward vector isVector3(0,0.5,0)

First thing, you are not using a normalized vector for the forward vector. If you say that its a forward vector, when moving on a flat plane, the forward.y component should be always 0, not 1. Or am I missing something?

so when you have your sphere on a slope, then the forward.y != 0, so when is that happening, you have to compute the angle between the slope and the ground, and just rotate the computed tween values with the computed angle around an axis orthogonal to your forward vector. After the values are rotated, then you can ignore forward.y and just compute the rest for x and z coordinates. If I've been unclear, please ask me more :D. hope it helps.

1. 1
2. 2
3. 3
4. 4
Rutin
16
5. 5

• 12
• 9
• 12
• 37
• 12
• ### Forum Statistics

• Total Topics
631417
• Total Posts
2999969
×
{"extraction_info": {"found_math": true, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 0, "mathjax_display_tex": 0, "mathjax_asciimath": 1, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0, "katex": 0, "math-container": 0, "wp-katex-eq": 0, "align": 0, "equation": 0, "x-ck12": 0, "texerror": 0, "math_score": 0.5989145636558533, "perplexity": 1144.0488528408255}, "config": {"markdown_headings": true, "markdown_code": true, "boilerplate_config": {"ratio_threshold": 0.18, "absolute_threshold": 10, "end_threshold": 15, "enable": true}, "remove_buttons": true, "remove_image_figures": true, "remove_link_clusters": true, "table_config": {"min_rows": 2, "min_cols": 3, "format": "plain"}, "remove_chinese": true, "remove_edit_buttons": true, "extract_latex": true}, "warc_path": "s3://commoncrawl/crawl-data/CC-MAIN-2018-26/segments/1529267865098.25/warc/CC-MAIN-20180623152108-20180623172108-00020.warc.gz"}