Skip to content

Instantly share code, notes, and snippets.

View BichengLUO's full-sized avatar
👨‍💻
Work at Google

Bicheng Luo BichengLUO

👨‍💻
Work at Google
View GitHub Profile
@BichengLUO
BichengLUO / nearest_point_between_two_lines.cpp
Last active January 23, 2023 22:31
Nearest point between two lines
//normal1: a 3d double vector indicating the normal vector of line1
//point1: a 3d double point indicating any point on line1
//normal2: a 3d double vector indicating the normal vector of line2
//point2: a 3d double point indicating any point on line2
//nearest_point: a 3d double point as the nearest point between line1 and line2
void nearest_point_between_two_lines(
const double *normal1, const double *point1,
const double *normal2, const double *point2,
double *nearest_point)
{
@BichengLUO
BichengLUO / Bilinear_Interpolation.cpp
Created January 29, 2015 06:53
Bilinear Interpolation
for (int i = 0; i < output.rows; i++)
{
uchar *out_data = output.ptr<uchar>(i);
for (int j = 0; j < output.cols; j++)
{
double ox;
double oy;
//Calculate the old point(ox, oy) according to j, i
//Thus, find a function f:(j, i)->(ox, oy) to get the result like (ox, oy)=f(j, i)
int x1 = ox < 0 ? 0 : ox;
@BichengLUO
BichengLUO / Git_Delete_Push
Created February 1, 2015 17:10
Git强制删除提交到远程版本库的数据与版本记录
git reset --hard HEAD~2 # 取消当前版本之前的两次提交
git push origin HEAD --force # 强制提交到远程版本库,从而删除之前的两次提交数据
@BichengLUO
BichengLUO / animate_round_path.mm
Created February 12, 2015 07:54
UIView animation along a round path
// Set up path movement
CAKeyframeAnimation *pathAnimation = [CAKeyframeAnimation animationWithKeyPath:@"position"];
pathAnimation.calculationMode = kCAAnimationPaced;
pathAnimation.fillMode = kCAFillModeForwards;
pathAnimation.removedOnCompletion = NO;
pathAnimation.repeatCount = INFINITY;
//pathAnimation.rotationMode = @"auto";
pathAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear];
pathAnimation.duration = 5.0;
@BichengLUO
BichengLUO / In-polygon.cpp
Created September 21, 2015 11:42
In-polygon test
bool in_polygon(const point &p, point ps[], int len)
{
int i, j = len - 1;
bool oddNodes = false;
for (i = 0; i < len; i++) {
if ((ps[i].y < p.y && ps[j].y >= p.y
|| ps[j].y < p.y && ps[i].y >= p.y)
&& (ps[i].x <= p.x || ps[j].x <= p.x))
{
@BichengLUO
BichengLUO / GravityCamera.cs
Last active November 30, 2021 00:37
A Unity3D script for rotating the camera according to the device's accelerometer
using UnityEngine;
using System.Collections;
using System;
using System.Collections.Generic;
public class GravityCamera : MonoBehaviour
{
public GameObject target;
public Vector3 centerOffset;
public float sensitivity = 1000;
@BichengLUO
BichengLUO / OneAngle.cs
Created June 7, 2016 07:11
A simple Unity3D script for generating 7 pics (1 key frame and 6 flow frames)
using UnityEngine;
using System.Collections;
using System;
public class OneAngle : MonoBehaviour {
public int shotCount;
public int radius = 5;
public Quaternion initialRotation;
public Vector3 initialPosition;
public float totalAngle;
@BichengLUO
BichengLUO / Antialiasing.cs
Created June 7, 2016 08:31
An antialiasing Unity3D script for camera
using System;
using UnityEngine;
namespace UnityStandardAssets.ImageEffects
{
public enum AAMode
{
FXAA2 = 0,
FXAA3Console = 1,
FXAA1PresetA = 2,
@BichengLUO
BichengLUO / ColorCorrectionCurves.cs
Created June 7, 2016 08:32
Correct color curves for camera in Unity3D
using System;
using UnityEngine;
namespace UnityStandardAssets.ImageEffects
{
[ExecuteInEditMode]
[AddComponentMenu ("Image Effects/Color Adjustments/Color Correction (Curves, Saturation)")]
public class ColorCorrectionCurves : PostEffectsBase
{
public enum ColorCorrectionMode
@BichengLUO
BichengLUO / DepthOfField.cs
Created June 7, 2016 08:33
Implement depth of field in Unity3D
using System;
using UnityEngine;
namespace UnityStandardAssets.ImageEffects
{
[ExecuteInEditMode]
[RequireComponent (typeof(Camera))]
[AddComponentMenu ("Image Effects/Camera/Depth of Field (Lens Blur, Scatter, DX11)") ]
public class DepthOfField : PostEffectsBase {