Skip to content

Instantly share code, notes, and snippets.

View EduardoJM's full-sized avatar

Eduardo Oliveira EduardoJM

View GitHub Profile
@EduardoJM
EduardoJM / funcoes_admissiveis.tex
Created October 23, 2019 19:41
Código LaTeX usando pacotes tikz plotando gráfico com funções admissiveis
%
% Código LaTeX usando pacotes tikz plotando gráfico com funções admissiveis
% Por Eduardo Oliveira (https://eduardojm.github.io)
%
\documentclass{standalone}
\usepackage{tikz}
\usepackage{tkz-fct}
\begin{document}
@EduardoJM
EduardoJM / sat_1.js
Created July 11, 2020 17:55
Separating Axis Theorem Helper Functions
function buildEdges(vertices) {
const edges = [];
if (vertices.length < 3) {
console.error("Only polygons supported.");
return edges;
}
for (let i = 0; i < vertices.length; i++) {
const a = vertices[i];
let b = vertices[0];
if (i + 1 < vertices.length) {
@EduardoJM
EduardoJM / sat_2.js
Created July 11, 2020 17:57
Separating Axis Theorem Polygon Structure
function createPolygon(vertices) {
const polygon = {};
polygon.vertices = vertices;
polygon.edges = buildEdges(vertices);
polygon.projectInAxis = function(x, y) {
}
polygon.testWith = function (otherPolygon) {
}
@EduardoJM
EduardoJM / sat_3.js
Created July 11, 2020 17:59
Separating Axis Theorem Polygon Offset
polygon.offset = function(dx, dy) {
for (let i = 0; i < polygon.vertices.length; i++) {
polygon.vertices[i] = {
x: polygon.vertices[i].x + dx,
y: polygon.vertices[i].y + dy,
};
}
};
@EduardoJM
EduardoJM / sat_4.js
Created July 11, 2020 18:00
Separating Axis Theorem Polygon Render Method
polygon.render = function(context, color) {
context.strokeStyle = color;
context.beginPath();
context.moveTo(
polygon.vertices[0].x,
polygon.vertices[0].y
);
for (let i = 1; i < polygon.vertices.length; i++) {
context.lineTo(
polygon.vertices[i].x,
@EduardoJM
EduardoJM / sat_5.js
Created July 11, 2020 18:07
Separating Axis Theorem Polygon in Axis Projection
polygon.projectInAxis = function(x, y) {
let min = 10000000000;
let max = -10000000000;
for (let i = 0; i < polygon.vertices.length; i++) {
let px = polygon.vertices[i].x;
let py = polygon.vertices[i].y;
var projection = (px * x + py * y) / (Math.sqrt(x * x + y * y));
if (projection > max) {
max = projection;
}
@EduardoJM
EduardoJM / sat_6.js
Created July 11, 2020 18:11
Separating Axis Theorem Collision Testing
polygon.testWith = function (otherPolygon) {
// get all edges
const edges = [];
for (let i = 0; i < polygon.edges.length; i++) {
edges.push(polygon.edges[i]);
}
for (let i = 0; i < otherPolygon.edges.length; i++) {
edges.push(otherPolygon.edges[i]);
}
// build all axis and project
@EduardoJM
EduardoJM / sat_7.js
Created July 11, 2020 18:15
Separating Axis Theorem Testing
const canvas = document.getElementById('game');
const context = canvas.getContext('2d');
const polygons = [];
const polygonsColors = [ 'red', 'blue', 'green', 'pink', 'purple', 'cyan' ];
polygons.push(createPolygon([
{ x: 50, y: 50 },
{ x: 100, y: 50 },
{ x: 100, y: 150 },
{ x: 50, y: 150 },
@EduardoJM
EduardoJM / sat_8.html
Created July 11, 2020 18:17
Separathing Axis Theorem Testing Html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<canvas id="game" width="512" height="512"></canvas>
@EduardoJM
EduardoJM / App.tsx
Created April 6, 2021 20:46
rn_text_1
import React, { useState } from 'react';
import { StatusBar } from 'expo-status-bar';
import { StyleSheet, Text, View } from 'react-native';