当前位置:  编程技术>移动开发
本页文章导读:
    ▪游戏中判断一群点能否构成凸多边形        游戏中判断一群点可否构成凸多边形     下面的代码需要box2d!!!!!!!!!!!import org.jbox2d.common.vec2;public class polyonutil {<br> private static polyonutil instance;<br> private float a;&l.........
    ▪ Java 推算日期(计算距今多少年,几多月,多少天的日期)        Java 推算日期(计算距今多少年,多少月,多少天的日期) import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; public final class Utils { /** * get any time which you want before or af.........
    ▪ 取ARGB色彩的分度值       取ARGB颜色的分度值 private static int getR32(int c) { return (c >> 0) & 0xFF; } // access the red component from a premultiplied color private static int getG32(int c) { return (c >> 8) & 0xFF; } .........

[1]游戏中判断一群点能否构成凸多边形
    来源: 互联网  发布时间: 2014-02-18
游戏中判断一群点可否构成凸多边形
    下面的代码需要box2d!!!!!!!!!!!
import org.jbox2d.common.vec2;
public class polyonutil {<br> private static polyonutil instance;<br> private float a;<br> private float b;<br> private boolean x_axis;<br> private boolean y_axis;<br> private float axis;<br> float i;
 public static polyonutil getinstance() {<br>  if (instance == null) {<br>   instance = new polyonutil();<br>  }<br>  return instance;<br> }
 public void setab(vec2 point1, vec2 point2) {<br>  if (point1.x == point2.x) {<br>   if (point1.y != point2.y) {<br>    y_axis = true;<br>    axis = point1.x;<br>   }<br>  } else if (point1.y == point2.y) {<br>   if (point1.x != point2.x) {<br>    x_axis = true;<br>    axis = point1.y;<br>   }<br>  } else {<br>   y_axis = false;<br>   x_axis = false;<br>   a = (point1.y - point2.y) / (point1.x - point2.x);<br>   b = point1.y - point1.x * a;<br>  }<br> }
 public byte getflag(vec2 point) {<br>  if (y_axis) {<br>   if (point.x > axis) {<br>    return 1;<br>   } else if (point.x < axis) {<br>    return -1;<br>   } else {<br>    return 0;<br>   }
  } else if (x_axis) {<br>   if (point.y > axis) {<br>    return 1;<br>   } else if (point.y < axis) {<br>    return -1;<br>   } else {<br>    return 0;<br>   }<br>  } else {<br>    i = point.y - a * point.x - b;<br>   if ((point.y - a * point.x - b) < 0) {<br>    return -1;<br>   } else if ((point.y - a * point.x - b) > 0) {<br>    return 1;<br>   } else {<br>    return 0;<br>   }<br>  }<br> }<br>}
//下面的函数判断一群点是否构成凸多边形
public boolean ishull(vec2[] mousestroke){
int mousestrokelength=mousestroke.length;
for (int i = 0; i < mousestrokelength; i+=2) {<br>   polyonutil.getinstance().setab(mousestroke[(i) % mousestrokelength],<br>     mousestroke[(i + 1) % mousestrokelength]);<br>   for (int j = 0, k = 0; j < mousestrokelength; j++) {<br>    if (j == i || j == (i + 1)) {<br>     continue;<br>    } else {<br>     flag[k] = polyonutil.getinstance().getflag(mousestroke[j<br>       % mousestrokelength]);<br>     k++;<br>    }<br>   }<br>   for (int l = 0; l < flag.length - 1; l++) {<br>    if (flag[l] * flag[l + 1] < 0) {<br>     // ao 当是凹多边形时候<br>          return false;<br>    }<br>   }<br>  }
return true;
}
 

    
[2] Java 推算日期(计算距今多少年,几多月,多少天的日期)
    来源: 互联网  发布时间: 2014-02-18
Java 推算日期(计算距今多少年,多少月,多少天的日期)
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public final class Utils
{
    
    /**
     * get any time which you want before or after today.
     * @param year  by number years(before or after this year) default:0
     * @param month by number months(before or after this month)default:0,no change
     * @param day   by number day(before or after this day)default:0,no change
     * @return
     */
    public static Date getCountDate(int year, int month, int day){
        
        Calendar cal = Calendar.getInstance ();
        cal.add (Calendar.YEAR, year);
        cal.add (Calendar.MONDAY, month);
        cal.add (Calendar.DATE, day);
        
        return cal.getTime ();
    }
    

    public static String dateToString (Date date)
    {
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        String temp = format.format (date);

        return temp;
    }
    
    public static void main(String[] args){

        Date today = Utils.getCountDate (0, 0, 0);
        Date oneYearBefore = Utils.getCountDate (-1, 0, 0);
        Date oneMonthBefore = Utils.getCountDate (0, -1, 0);
        Date oneDayBefore = Utils.getCountDate (0, 0, -1);
        Date oneYearAfter = Utils.getCountDate (1, 0, 0);
        Date oneMonthAfter = Utils.getCountDate (0, 1, 0);
        Date oneDayAfter = Utils.getCountDate (0, 0, 1);
        
        System.out.println (today + "\t" + Utils.dateToString (today));
        System.out.println (oneYearBefore + "\t" + Utils.dateToString (oneYearBefore));
        System.out.println (oneMonthBefore + "\t" + Utils.dateToString (oneMonthBefore));
        System.out.println (oneDayBefore + "\t" + Utils.dateToString (oneDayBefore));
        System.out.println (oneYearAfter + "\t" + Utils.dateToString (oneYearAfter));
        System.out.println (oneMonthAfter + "\t" + Utils.dateToString (oneMonthAfter));
        System.out.println (oneDayAfter + "\t" + Utils.dateToString (oneDayAfter));
    }
}

 

Result:

 

Mon Oct 24 16:09:45 CST 2011 2011-10-24
Sun Oct 24 16:09:45 CST 2010 2010-10-24
Sat Sep 24 16:09:45 CST 2011 2011-09-24
Sun Oct 23 16:09:45 CST 2011 2011-10-23
Wed Oct 24 16:09:45 CST 2012 2012-10-24
Thu Nov 24 16:09:45 CST 2011 2011-11-24
Tue Oct 25 16:09:45 CST 2011 2011-10-25

 

 


    
[3] 取ARGB色彩的分度值
    来源: 互联网  发布时间: 2014-02-18
取ARGB颜色的分度值

        private static int getR32(int c) { return (c >>  0) & 0xFF; }
        // access the red component from a premultiplied color
        private static int getG32(int c) { return (c >>  8) & 0xFF; }
        // access the red component from a premultiplied color
        private static int getB32(int c) { return (c >> 16) & 0xFF; }
        // access the red component from a premultiplied color
        private static int getA32(int c) { return (c >> 24) & 0xFF; }
 

    
最新技术文章:
▪Android开发之登录验证实例教程
▪Android开发之注册登录方法示例
▪Android获取手机SIM卡运营商信息的方法
▪Android实现将已发送的短信写入短信数据库的...
▪Android发送短信功能代码
▪Android根据电话号码获得联系人头像实例代码
▪Android中GPS定位的用法实例
▪Android实现退出时关闭所有Activity的方法
▪Android实现文件的分割和组装
▪Android录音应用实例教程
▪Android双击返回键退出程序的实现方法
▪Android实现侦听电池状态显示、电量及充电动...
▪Android获取当前已连接的wifi信号强度的方法
▪Android实现动态显示或隐藏密码输入框的内容
▪根据USER-AGENT判断手机类型并跳转到相应的app...
▪Android Touch事件分发过程详解
▪Android中实现为TextView添加多个可点击的文本
▪Android程序设计之AIDL实例详解
▪Android显式启动与隐式启动Activity的区别介绍
▪Android按钮单击事件的四种常用写法总结
▪Android消息处理机制Looper和Handler详解
▪Android实现Back功能代码片段总结
▪Android实用的代码片段 常用代码总结
▪Android实现弹出键盘的方法
▪Android中通过view方式获取当前Activity的屏幕截...
▪Android提高之自定义Menu(TabMenu)实现方法
▪Android提高之多方向抽屉实现方法
▪Android提高之MediaPlayer播放网络音频的实现方法...
▪Android提高之MediaPlayer播放网络视频的实现方法...
sqlserver iis7站长之家
 


站内导航:


特别声明:169IT网站部分信息来自互联网,如果侵犯您的权利,请及时告知,本站将立即删除!

©2012-2021,,E-mail:www_#163.com(请将#改为@)

浙ICP备11055608号-3