# Unity Get Array of Points that Make a Circle And Displace Them

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

## Recommended Posts

Hi, so I'm trying to figure out a world generation algorithm for my game in Unity but I am having a hard time deciding how to implement it.

So few days ago, I stumbled on an old thread in this site which they achieve exactly what I am trying to do. They generate some circles and then use Perlin noise to mess with radius (or at least that's what I understood so far), resulting in irregular continents.

I tried using "if (x-x0)^2 + (y-y0)^2 <= r^2 then" but the thing is, I don't get the same result

According to that thread, their way of drawing a circle is using function that has a theta, but I can't find a way of doing that.
So my question is: How Can I get an array of points that make up a circle (NOT CIRCUMFERENCE) so that I can get the same results as the image bellow?

The reason I don't ask in that thread its because its already too old and is locked.

##### Share on other sites

Are you talking about the parametric equation of a circle? You have to decide how many points your circle will have and then you can calculate theta accordingly, e.g.:

Vector2[] circle = new Vector2[numVertices];
float delta = (2*PI) / numVertices;

for (int i=0; i < numVertices; i++)
{
float t = delta * i;
x = x0 + cos(t)*r;
y = y0 + sin(t)*r;
circle[i] = new Vector2(x,y);
}


Where x0,y0 are the coordinates of your center and r is the radius of the circle. As the for loop runs, t will be incremented until it covers the whole circle. The more points you calculate, the closer it will approximate a circle.

Edited by AvengerDr

##### Share on other sites

their way of drawing a circle is using function that has a theta, but I can't find a way of doing that.

Theta is an angle incremented from 0 to 2 Pi, commonly in a loop to generate (x,y) coordinate pairs.

Off the top of my head:

float delta = (some small value);
for(float theta = 0; theta < 2*Pi; theta += delta)
{
float x = sin(theta);
float y = cos(theta);
// use (x,y) for something
}

by AvengerDr

Edited by Buckeye

##### Share on other sites

Thanks for your post, my problem is that using a parametric function, I just have the points surrounding the center, not actually the filled circle.

##### Share on other sites

If for each iteration in the loop you add a random displacement to the radius, you will get a circle with jagged segments - if you were to connect all the vertices to each other. In fact, this set of points could then be transformed into a polyline or spline and filled accordingly to your requirements.

Edited by AvengerDr

##### Share on other sites

You do know that there are other potentially easier ways to create continents, right? Such as height maps or incremental flood fill..

Looking at those images, I'm guessing they are using very close points, possibly with variations in the theta as well as the radius. If you are interested in this for mathematical reasons or whatever, then by all means, but if you just want nice continents, there are probably easier ways.

##### Share on other sites

I tried to take the challenge to make my own implementation, knowing nothing about the subject at all.  It looks nothing like the images you showed.  Then I noticed that they are using Perlin noise, and I was just using a simple random generator...  Basically using the method AvengerDr suggested, drawing a circle with various displacements, deformations.  (Basically drawing a jagged oval rather than a jagged circle.)

Edit: Looking at the picture you posted, it looks like they are not only using Perlin noise, but using spherical coordinates too.  (Mapping to a sphere.)

On the other hand, looking at the picture from the answer in the thread that you posted a link to, the initial shapes looks very much like what I get with my attempt.

Picture prom the post:

Code (quick and dirty...)

- (void)drawRect:(NSRect)dirtyRect {

[[NSColor blackColor] set];
[NSBezierPath fillRect:dirtyRect];

[[NSColor whiteColor] set];

double centerX = [self bounds].size.width / 2.0f;
double centerY = [self bounds].size.height / 2.0f;

double x = 0.0f;
double y = 0.0f;

double delta = 0.05f;

double randomValue = 0.0f;

randomValue = (double)arc4random_uniform(10000) / 10000.0f;
double scaleX = (randomValue + 0.1f);

randomValue = (double)arc4random_uniform(10000) / 10000.0f;
double scaleY = (randomValue + 0.1f);

randomValue = (double)arc4random_uniform(10000) / 10000.0f;
double clampToValue = randomValue * 200.0f;

NSBezierPath *circle = [NSBezierPath bezierPath];
BOOL isFirst = YES;

for (double theta = 0.0f; theta < 2 * M_PI; theta += delta) {
randomValue = ((double)arc4random_uniform(10000) / 10000.0f) - 0.5f;

}

if (isFirst) {
[circle moveToPoint:NSMakePoint(x, y)];
isFirst = NO;
}
else {
[circle lineToPoint:NSMakePoint(x, y)];
}

}

[circle closePath];
[circle fill];
//    [circle stroke];
}


Edited by aregee

• 10
• 11
• 9
• 16
• 18
• ### Similar Content

• Another one of our new UI for #screenshotsaturday. This is the inventory screen for showing what animal fossils you have collected so far. #gamedev #indiedev #sama

• We're looking for programmers for our project.
Our project is being made in Unity
Requirements:
-Skills in Unity
-C#
-Javascript
-Node.js
We're looking for programmers who can perform a variety of functions on our project.
Project is a top-down hack-and-slash pvp dungeon-crawler like game. Game is entirely multiplayer based, using randomized dungeons, and a unique combat system with emphasis on gameplay.
We have a GDD to work off of, and a Lead Programmer you would work under.
Assignments may include:
-Creating new scripts of varying degrees specific to the project (mostly server-side, but sometimes client-side)
-Assembling already created monsters/characters with existing or non-existing code.
-Creating VFX
This project is unpaid, but with royalties.

---
Summary:
Bassetune Reapers is a Player-verus-Player, competitive dungeon crawler. This basically takes on aspects of dungeon crawling, but with a more aggressive setting. Players will have the option to play as the "dungeon-crawlers" (called the 'Knights', or "Knight Class", in-game) or as the "dungeon" itself (literally called the 'Bosses', or "Boss Class", in-game). What this means is that players can choose to play as the people invading the dungeon, or as the dungeon-holders themselves.
Key Features:
-Intense, fast-paced combat
-Multiple skills, weapons, and ways to play the game
-Tons of different Bosses, Minibosses, creatures and traps to utilize throughout the dungeon
-Multiple unique environments
-Interesting, detailed lore behind both the game and world
-Intricate RPG system
-Lots of customization for both classes s of customization for both classes

• Custom coffee mugs have arrived... More caffeine!
Have a great weekend everyone!
#gamedev #indiedev #sama #caffeine

•
Hey guys,

Anthony here from Atwo Studios bringing you some new updates for the new year!
In this video I go over our game ROY, the new games and some general updates to the company!

If you have not checked out ROY feel free to give it a try! Many people have said they enjoyed the game thus far!
ROY: https://goo.gl/o6JJ5P

• By Affgoo