• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
MARS_999

Help with this formula...

16 posts in this topic

I am not sure how to make this formula work...

 

Let’s say we had a very weird two dimensional, sinusoidal topography such that z = f(x) = sinx with z the height and x is the distance from some marker. The slope in the x direction 70229138.png

 

I am trying to convert the scalar field (height versus position) to a vector field (direction and magnitude of greatest slope) mathematically

0

Share this post


Link to post
Share on other sites

So you're trying to find the gradient of f (denoted as ?f)?

 

[attachment=13003:z.png]

[attachment=13004:gradient.png]

 

Then:

 

[attachment=13005:solved.png]

 

Also, did your "The slope in the x direction" sentence get cut off?

 

I'll be honest, I'm not entirely sure what you're after, and it's possible you're after something different than the ?f, but to be honest your post isn't incredibly clear.

Edited by Cornstalks
0

Share this post


Link to post
Share on other sites

Thanks for the reply.

 

Here is what the article says....

 

We often wish to differentiate a function along three orthogonal axes. For example, imagine we know the topography of a ski area (see Figure A.6). For every location (in say, X and Y coordinates), we know the height above sea level. This is a scalar function. Now imagine we want to build a ski resort, so we need to know the direction of steepest descent and the slope (red arrows in Figure A.6).

 

To convert the scalar field (height versus position) to a vector field (direction and magnitude of greatest slope) mathematically, we would simply differentiate the topography function. Let’s say we had a very weird two dimensional, sinusoidal topography such that z = f(x) = sinx with z the height and x is the distance from some marker. The slope in the x direction (), then would be d _ dxf(x). If f(x,y,z) were a three dimentional topography then the gradient of the topography function would be:

 

So from the looks of it yes, a Gradient...

 

So lets say we have (x,y) as (10, 100)

 

then

 

z=sin(x);??

 

post-67860-0-55136700-1356752592.png

 

as for that I am not sure what comes after the cosine()....

 

Thanks!

Edited by MARS_999
0

Share this post


Link to post
Share on other sites
The gradient is a vector field. The first coordinate of the vector at (x,y) will be (d/dx)f(x,y) and the second coordinate will be (d/dy)f(x,y). It looks like your source is referring to the vector field that is (1,0) everywhere as x with a hat and (0,1) as y with a hat. It is more standard to refer to them as (d/dx) and (d/dy) with the funny `d's that are used for partial differentiation (although that notation can be extremely confusing to non-geometrists).

So if you have (x,y) as (10,100), the gradient of your function f at that point is the vector (cos(10), 0).

I hope that clears things up.
0

Share this post


Link to post
Share on other sites

That helps Alvaro, but why is cos(10),0 and not cos(10), 100??

 

so with a x,y pair of 10,100

 

the result xyz vector would be??

 

x,y, z= (cos(10), 100, sin(10)?

0

Share this post


Link to post
Share on other sites
Forget z for a moment. You have a function in two dimensions (x and y) and its gradient is a two-dimensional vector field. You can look at the function as being the coordinate z, but then you are talking about the graph of the function, not the function itself.
0

Share this post


Link to post
Share on other sites

So is this correct then?

 

[code]double Gradient(const std::vector<double> &v)
{
    return sin(v[0]) + 2 * cos(v[1]) - sin(v[2]);
}   std::vector<double> v;
    v.push_back(1);
    v.push_back(1);
    v.push_back(1);
    std::cout << Gradient(v) << std::endl; //result = 1.0806[/code]

 

but aren't I looking for these values?

     x(0) = 1.570795457
     x(1) = 6.423712373e-006
     x(2) = 4.712391906

 

If so how do I get to that  result?

0

Share this post


Link to post
Share on other sites
There are several problems with that code. First of all, you probably don't want to use std::vector to represent vectors. Despite the tempting name, std::vector is actually a dynamic array. Vectors are things you can add, subtract and scale. You can't do any of these things with std::vector.

A bigger problem with your code is that you are returning a double from Gradient, but the gradient is a vector, not a real number.

It's also hard to know if your Gradient function does the right thing if I don't know what function it's supposed to be the gradient of.

This is the kind of thing I would write:
#include <iostream>
#include <cmath>

struct Vector3D {
  double x, y, z;

  Vector3D(double x, double y, double z) : x(x), y(y), z(z) {
  }
};

std::ostream &operator<<(std::ostream &os, Vector3D v) {
  return os << '(' << v.x << ',' << v.y << ',' << v.z << ')';
}

double f(Vector3D v) {
  return std::sin(v.x) + std::cos(v.y);
}

Vector3D Gradient(Vector3D v) {
  return Vector3D(std::cos(v.x), -std::sin(v.y), 0.0);
}

int main() {
  Vector3D v(1.0, 1.0, 1.0);

  std::cout << Gradient(v) << std::endl;
}
0

Share this post


Link to post
Share on other sites

I am trying to calculate the slope of a point given X,Y coordinates... HTH you help me :)

0

Share this post


Link to post
Share on other sites

There is no such thing as the slope of a point. There is a notion of the slope of a function along a direction, formally known as the directional derivative. Among the directional derivatives corresponding to directions with length 1, the maximum is achieved in the direction of the gradient.

 

So, do you want to compute the direction in which the function grows fastest (the gradient), or how fast it grows in that direction (the directional derivative in the direction of the gradient), or something else?

1

Share this post


Link to post
Share on other sites

The former I assume?

 

Normals are -1 to 1 and wouldn't that be a derivative? So if you could please show both forms and I can try them both and see what the results are... and see if I like the results it shows?

 

Thanks

0

Share this post


Link to post
Share on other sites

I am not done asking questions. :)

 

So you have a terrain described as a 2D heightmap. I assume that means you know the elevation of the terrain at the points of a grid. However, normals, gradients and all these things are only defined if you know the elevation of any point, not just the ones in the grid. You could use an interpolation method to extend the function to non-grid points in a reasonable manner, but perhaps this is beyond what you intend to do.

 

Alternatively, you can use discreet approximations to these things. If you do that, the gradient at (x,y) is simply the vector (height(x+1,y)-height(x,y), height(x,y+1)-height(x,y)).

 

Are we getting closer?

0

Share this post


Link to post
Share on other sites

If I have a grid say 64x64 then 0-63 in the x direction and 0-63 in the y direction, with each grid point holds the height(elevation) yes I know that data. That point could be anywhere from 0 to skys the limit.... :)

0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0