Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Circle intersect #335

Open
wants to merge 21 commits into
base: usage-examples
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 19 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
using SplashKitSDK;

namespace CircleIntersectExample
{
public class Program
{
public static void Main()
{
// Read the data for Circle A
SplashKit.WriteLine("X coordinate for circle A: ");
int X_A = SplashKit.ConvertToInteger(SplashKit.ReadLine());
SplashKit.WriteLine("Y coordinate for circle A: ");
int Y_A = SplashKit.ConvertToInteger(SplashKit.ReadLine());
SplashKit.WriteLine("Radient for circle A: ");
int R_A = SplashKit.ConvertToInteger(SplashKit.ReadLine());

// Create circle A based on the user's data
Circle A = SplashKit.CircleAt(X_A, Y_A, R_A);

//Read the data for Circle B
SplashKit.WriteLine("X coordinate for circle B: ");
int X_B = SplashKit.ConvertToInteger(SplashKit.ReadLine());
SplashKit.WriteLine("Y coordinate for circle B: ");
int Y_B = SplashKit.ConvertToInteger(SplashKit.ReadLine());
SplashKit.WriteLine("Radient for circle B: ");
int R_B = SplashKit.ConvertToInteger(SplashKit.ReadLine());

// Create circle B based on the user's data
Circle B = SplashKit.CircleAt(X_B, Y_B, R_B);

// Detect if the circles intersect
if (SplashKit.CirclesIntersect(A, B))
{
SplashKit.WriteLine("The circles intersect!");
}
else
{
SplashKit.WriteLine("The circles do not intersect!");
}

// Create a window
SplashKit.OpenWindow("Circle Intersect", 800, 600);
SplashKit.ClearScreen();

// Draw the circles based on the data given by user
SplashKit.DrawCircle(Color.Red, X_A, Y_A, R_A);
SplashKit.DrawCircle(Color.Red, X_B, Y_B, R_B);

SplashKit.RefreshScreen();
SplashKit.Delay(4000);
SplashKit.CloseAllWindows();
}
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
using SplashKitSDK;
using static SplashKitSDK.SplashKit;

// Read the data for Circle A
WriteLine("X coordinate for circle A: ");
int X_A = ConvertToInteger(ReadLine());
WriteLine("Y coordinate for circle A: ");
int Y_A = ConvertToInteger(ReadLine());
WriteLine("Radient for circle A: ");
int R_A = ConvertToInteger(ReadLine());

// Create circle A based on the user's data
Circle A = CircleAt(X_A, Y_A, R_A);

// Read the data for Circle B
WriteLine("X coordinate for circle B: ");
int X_B = ConvertToInteger(ReadLine());
WriteLine("Y coordinate for circle B: ");
int Y_B = ConvertToInteger(ReadLine());
WriteLine("Radient for circle B: ");
int R_B = ConvertToInteger(ReadLine());

// Create circle B based on the user's data
Circle B = CircleAt(X_B, Y_B, R_B);

// Detect if the circles intersect
if (CirclesIntersect(A, B))
{
WriteLine("The circles intersect!");
}
else
{
WriteLine("The circles do not intersect!");
}

// Create a window
OpenWindow("Circle Intersect", 800, 600);
ClearScreen();

// Draw the circles based on the data given by user
DrawCircle(Color.Red, X_A, Y_A, R_A);
DrawCircle(Color.Red, X_B, Y_B, R_B);

RefreshScreen();
Delay(4000);
CloseAllWindows();

Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#include "splashkit.h"

int main()
{
// Read the data for Circle A
write_line("X coordinate for circle A: ");
int X_A = convert_to_integer(read_line());
write_line("Y coordinate for circle A: ");
int Y_A = convert_to_integer(read_line());
write_line("Radient for circle A: ");
int R_A = convert_to_integer(read_line());

// Create circle A based on the user's data
circle A = circle_at(X_A, Y_A, R_A);

// Read the data for Circle B
write_line("X coordinate for circle B: ");
int X_B = convert_to_integer(read_line());
write_line("Y coordinate for circle B: ");
int Y_B = convert_to_integer(read_line());
write_line("Radient for circle B: ");
int R_B = convert_to_integer(read_line());

// Create circle B based on the user's data
circle B = circle_at(X_B, Y_B , R_B);

// Detect if the circles intersect
if(circles_intersect(A, B))
{
write_line("The circles intersect!");
}
else{
write_line("The circles do not intersect!");
}

// Create a window
open_window("Circle Intersect", 800, 600);
clear_screen();

// Draw the circles based on the data given by user
draw_circle(COLOR_RED, X_A, Y_A, R_A);
draw_circle(COLOR_RED, X_B, Y_B, R_B);

refresh_screen();
delay(4000);
close_all_windows();
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The window title in your screen shot does not match the code. Currently shows PointAt rather than Circle Intersect

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
from splashkit import *

# Read the data for Circle A
write_line("X coordinate for circle A: ")
X_A = convert_to_integer(read_line())
write_line("Y coordinate for circle A: ")
Y_A = convert_to_integer(read_line())
write_line("Radient for circle A: ")
R_A = convert_to_integer(read_line())

# Create circle A based on the user's data
A = circle_at(point_at(X_A, Y_A), R_A)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you could use circle_at_from_points here to match the overloaded functions used in the other files and not have to use point_at here.


# Read the data for Circle B
write_line("X coordinate for circle B: ")
X_B = convert_to_integer(read_line())
write_line("Y coordinate for circle B: ")
Y_B = convert_to_integer(read_line())
write_line("Radient for circle B: ")
R_B = convert_to_integer(read_line())

# Create circle B based on the user's data
B = circle_at(point_at(X_B, Y_B), R_B)

# Detect if the circles intersect
if (circles_intersect(A, B)):
write_line("The circles intersect!")
else:
write_line("The circles do not intersect!")

# Create a window
open_window("Circle Intersect", 800, 600)
clear_screen(color_white())

# Draw the circles based on the data given by user
draw_circle(color_red(), X_A, Y_A, R_A)
draw_circle(color_red(), X_B, Y_B, R_B)

refresh_screen()
delay(4000)
close_all_windows()




Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#### Circles Intersection Detect System

The following code shows examples of using [Circles Intersect](/api/geometry/#circles-intersect-1) to show how to detect if two circle A and B intersect or not.