Geometric algorithms for mobile games to draw touch-screen control Disks

Source: Internet
Author: User

Geometric graphics computing is often applied to the development of games or other complex UIS. The following describes the coordinates of known straight lines and circles used in the development of games. · When an object's activity range is limited to the range of the circle o, you can drag it to move, that is, the coordinate of the object follows a in the area of the circle, after dragging point a out of the circle area, the object can only move to the boundary of the circle, and keep the line between A and O, so there is a mathematical problem: is the intersection of line AO and circle o e (xe, ye )?

This is a common mathematical problem, but how to implement this through programmingAlgorithmWhat about it? If you calculate the result by calculating the straight line expression and the circle expression and then solving the equation, it becomes more complicated and two solutions are obtained. It is not necessary to carefully observe the complex calculation formula. First, line AO is actually a vector OA, with only one direction and only one intersection with the circle. Therefore, we can analyze the right triangle principle. That is, relational R/OA = (Xe-XO)/(xA-XO)

After the conversion, write the following in Java:

Float XO = 100f; float yo = 100f; float r = 50f; // radiusfloat OA = (float) math. SQRT (xA-XO) * (xA-XO) + (ya-yo) * (ya-yo); float Xe = XO + (xA-XO) * r/OA; float ye = Yo + (ya-yo) * R/OA;

As a result, the key algorithms used to draw the wheel in the control direction disc of mobile phone games with touch screens can be implemented through this formula.
 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.