Дизайн-версия Android-платформы

Я бы использовал алгоритм для вычисления расстояния между точкой (центром окружности) и линией (строка AB). Это можно затем использовать для определения точек пересечения прямой с кружком.

Пусть, скажем, мы имеем точки A, B, C. Ax и Ay - х и y-компоненты точек A. То же самое для B и C. Скаляр R - радиус окружности.

Вот алгоритм

// compute the euclidean distance between A and B
LAB = sqrt( (Bx-Ax)²+(By-Ay)² )

// compute the direction vector D from A to B
Dx = (Bx-Ax)/LAB
Dy = (By-Ay)/LAB

// Now the line equation is x = Dx*t + Ax, y = Dy*t + Ay with 0 <= t <= 1.

// compute the value t of the closest point to the circle center (Cx, Cy)
t = Dx*(Cx-Ax) + Dy*(Cy-Ay)    

// This is the projection of C on the line from A to B.

// compute the coordinates of the point E on line and closest to C
Ex = t*Dx+Ax
Ey = t*Dy+Ay

// compute the euclidean distance from E to C
LEC = sqrt( (Ex-Cx)²+(Ey-Cy)² )

// test if the line intersects the circle
if( LEC < R )
{
    // compute distance from t to circle intersection point
    dt = sqrt( R² - LEC²)

    // compute first intersection point
    Fx = (t-dt)*Dx + Ax
    Fy = (t-dt)*Dy + Ay

    // compute second intersection point
    Gx = (t+dt)*Dx + Ax
    Gy = (t+dt)*Dy + Ay
}

// else test if the line is tangent to circle
else if( LEC == R )
    // tangent point to circle is E

else
    // line doesn't touch circle
-1
задан mostafa zaghloul 13 July 2018 в 15:37
поделиться

1 ответ

Создайте все представления в файле .xml или в нескольких после их включения в основной файл view.xml

<include
    android:id="@+id/vista1"
    layout="@layout/vista1"
    android:visibility="gone"/>

<include
    android:id="@+id/vista2"
    layout="@layout/vista2"
    android:visibility="gone"/>

или

<LinearLayout android:id="@+id/vista1" android:visibility="gone"> ... </LinearLayout>
<LinearLayout android:id="@+id/vista2" android:visibility="gone"> ... </LinearLayout>

в соответствии с вашим представлением если он является линейным, relativelayout в вашем классе java

LinearLayout vista1 = (LinearLayout) findViewById(R.id.vista1);
LinearLayout vista2 = (LinearLayout) findViewById(R.id.vista2);
....
vista1.setVisibility(View.GONE);
vista2.setVisibility(View.VISIBLE);

Надеюсь помочь

1
ответ дан Julio Cesar Caicedo 17 August 2018 в 12:30
поделиться
Другие вопросы по тегам:

Похожие вопросы: