una tipos teoria relativas relaciones puntos punto posiciones interior entre ecuacion circunferencias circunferencia calcular algorithm math trigonometry circle

algorithm - tipos - teoria de la circunferencia



Cálculo de la posición de los puntos en un círculo (10)

Aquí hay una solución que usa C #:

void DrawCirclePoints(int points, double radius, Point center) { double slice = 2 * Math.PI / points; for (int i = 0; i < points; i++) { double angle = slice * i; int newX = (int)(center.X + radius * Math.Cos(angle)); int newY = (int)(center.Y + radius * Math.Sin(angle)); Point p = new Point(newX, newY); Console.WriteLine(p); } }

Muestra de salida de DrawCirclePoints(8, 10, new Point(0,0)); :

{X=10,Y=0} {X=7,Y=7} {X=0,Y=10} {X=-7,Y=7} {X=-10,Y=0} {X=-7,Y=-7} {X=0,Y=-10} {X=7,Y=-7}

¡Buena suerte!

Estoy teniendo un poco de mente en blanco en esto en este momento. Tengo un problema donde necesito calcular la posición de los puntos alrededor de un punto central, suponiendo que están todos equidistantes del centro y uno del otro.

El número de puntos es variable, así que es DrawCirclePoints(int x) Estoy seguro de que hay una solución simple, pero por mi vida, simplemente no puedo verlo :)


Aquí hay una versión R basada en la respuesta @Pirijan anterior.

points <- 8 radius <- 10 center_x <- 5 center_y <- 5 drawCirclePoints <- function(points, radius, center_x, center_y) { slice <- 2 * pi / points angle <- slice * seq(0, points, by = 1) newX <- center_x + radius * cos(angle) newY <- center_y + radius * sin(angle) plot(newX, newY) } drawCirclePoints(points, radius, center_x, center_y)


Dada una longitud de radio ry un ángulo t en radianes y el centro de un círculo (h, k) , puede calcular las coordenadas de un punto en la circunferencia de la siguiente manera (esto es un pseudocódigo, deberá adaptarlo a su idioma):

float x = r*cos(t) + h; float y = r*sin(t) + k;


El ángulo entre cada uno de tus puntos va a ser 2Pi/x así que puedes decir que para los puntos n= 0 to x-1 el ángulo desde un punto definido es 2nPi/x .

Suponiendo que su primer punto está en (r,0) (donde r es la distancia desde el punto central), entonces las posiciones relativas al punto central serán:

rCos(2nPi/x),rSin(2nPi/x)


Para completar, lo que describes como "posición de puntos alrededor de un punto central (suponiendo que estén todos equidistantes del centro)" no es más que "Coordenadas polares". Y está pidiendo la forma de Convertir entre coordenadas polares y Cartesianas que se da como x = r cos (t), y = r sin (t).


Solución de PHP:

class point{ private $x = 0; private $y = 0; public function setX($xpos){ $this->x = $xpos; } public function setY($ypos){ $this->y = $ypos; } public function getX(){ return $this->x; } public function getY(){ return $this->y; } public function printX(){ echo $this->x; } public function printY(){ echo $this->y; } }

function drawCirclePoints($points, $radius, &$center){ $pointarray = array(); $slice = (2*pi())/$points; for($i=0;$i<$points;$i++){ $angle = $slice*$i; $newx = (int)(($center->getX() + $radius) * cos($angle)); $newy = (int)(($center->getY() + $radius) * sin($angle)); $point = new point(); $point->setX($newx); $point->setY($newy); array_push($pointarray,$point); } return $pointarray; }


Solución de trabajo en Java:

import java.awt.event.*; import java.awt.Robot; public class CircleMouse { /* circle stuff */ final static int RADIUS = 100; final static int XSTART = 500; final static int YSTART = 500; final static int DELAYMS = 1; final static int ROUNDS = 5; public static void main(String args[]) { long startT = System.currentTimeMillis(); Robot bot = null; try { bot = new Robot(); } catch (Exception failed) { System.err.println("Failed instantiating Robot: " + failed); } int mask = InputEvent.BUTTON1_DOWN_MASK; int howMany = 360 * ROUNDS; while (howMany > 0) { int x = getX(howMany); int y = getY(howMany); bot.mouseMove(x, y); bot.delay(DELAYMS); System.out.println("x:" + x + " y:" + y); howMany--; } long endT = System.currentTimeMillis(); System.out.println("Duration: " + (endT - startT)); } /** * * @param angle * in degree * @return */ private static int getX(int angle) { double radians = Math.toRadians(angle); Double x = RADIUS * Math.cos(radians) + XSTART; int result = x.intValue(); return result; } /** * * @param angle * in degree * @return */ private static int getY(int angle) { double radians = Math.toRadians(angle); Double y = RADIUS * Math.sin(radians) + YSTART; int result = y.intValue(); return result; } }


Tenía que hacer esto en la web, así que aquí hay una versión en respuesta de @ :

points = 8 radius = 10 center = {x: 0, y: 0} drawCirclePoints = (points, radius, center) -> slice = 2 * Math.PI / points for i in [0...points] angle = slice * i newX = center.x + radius * Math.cos(angle) newY = center.y + radius * Math.sin(angle) point = {x: newX, y: newY} console.log point drawCirclePoints(points, radius, center)


Un punto en ángulo theta en el círculo cuyo centro es (x0,y0) y cuyo radio es r es (x0 + r cos theta, y0 + r sin theta) . Ahora elija theta valores espaciados uniformemente entre 0 y 2pi.


Usando una de las respuestas anteriores como base, aquí está el ejemplo de Java / Android:

protected void onDraw(Canvas canvas) { super.onDraw(canvas); RectF bounds = new RectF(canvas.getClipBounds()); float centerX = bounds.centerX(); float centerY = bounds.centerY(); float angleDeg = 90f; float radius = 20f float xPos = radius * (float)Math.cos(Math.toRadians(angleDeg)) + centerX; float yPos = radius * (float)Math.sin(Math.toRadians(angleDeg)) + centerY; //draw my point at xPos/yPos }