I am working on a project that needs to fill the cells of a 2D Array with the proper values in order to build two shapes, a pyramid and a cone. I will immensely appreciate any help on implementing this algorithm. Basically, I need to pass the x and y coordinates of the 2D Array and the function should return the proper height value at those coordinates. The minimum height is 0 and the maximum height is 100.
My functions have the following prototypes:
float getPyramidHeight(int x, int y)
{
}
float getConeHeight(int x, int y)
{
}
Basically, I have 2 variables:
w = 2D Array Length
and
h = 2D Array Width
This is where I am at right now:
#include <iostream>
#include <stdio.h>
using namespace std;
#define LENGTH 1000
#define WIDTH 800
float pyramidHeights[LENGTH][WIDTH]={0};
float coneHeights[LENGTH][WIDTH]={0};
float getPyramidHeight(int x, int y);
float getConeHeight(int x, int y);
void fillPyramid(int x, int y);
void fillCone(int x, int y);
int main()
{
fillPyramid(LENGTH, WIDTH);
fillCone(LENGTH, WIDTH);
return 0;
}
void fillPyramid(int x, int y)
{
for(int i=0;i<x;i++)
{
for(int j=0;j<y;j++)
{
pyramidHeights[i][j]=getPyramidHeight(i,j);
}
}
}
void fillCone(int x, int y)
{
for(int i=0;i<x;i++)
{
for(int j=0;j<y;j++)
{
coneHeights[i][j]=getConeHeight(i,j);
}
}
}
float getPyramidHeight(int x, int y)
{
//This is the first function I need to implement.
return 0;
}
float getConeHeight(int x, int y)
{
//This is the second function I need to implement.
return 0;
}
I know it's not complete but this is as far as I could go. Thank you for your time!