2d – Can I linearly interpolate colors along the X and Y axes of a circle rather than using the distance formula for each individual point?

Mathematically, it is not equivalent.

I would like to preface this by saying; "But if it works for you, is more powerful, and the player does not notice it, then you still are, games are nothing but smoke and mirrors."

The easiest way to check if this works or not is to test a simple linear interpolation on a radius 1 circle.

Here we can intuitively see that the value in the middle is 0 and the value at the edges is "1". That is, on this unit circle, the value of a point corresponds to the distance of that point from the center.

This makes it much easier to think about it. Now we can choose any point. If we know how far from the center he is, we know how high the value should be. We can then use your interpolation method. and if the values ​​match, we know that your method is correct.

Use the following picture:

Circular image showing how the parts are used in the following equations.

It is clear that every radius that comes from the center of the circle (marked O) must begin with the distance 0 and must interpolate linearly to the distance 1. As such, the center of such a radius would have a value of 0.5 – as marked.

For a radius of 45 *, the same applies. However, selecting such an angle facilitates the following calculations.

It can be seen that the center of this 45 * line (value 0.5) projects at a certain distance on the x- and y-axis. These are labeled A (y-axis) and B (x-axis).

If we interpolate according to your method from O-> A on the y-axis and then interpolate from there on the x-axis to B, we should get the same value as the distance calculation.

From the basic trigger we can calculate the A and B components from the 45 * angle and the length of the hypotenuse (which is intuitively 0.5):

 O->A = 0.5 * cos(45degrees)
      = 1 / (2sqrt(2)))

 O->B = 0.5 * sin(45degrees)
      = 1 / (2sqrt(2)))

From this we can then use your interpolation method:

Starting with 1 / (2sqrt (2)) on the y-axis we interpolate in the direction of the x-axis along the B-units.

The general form of linear interpolation is:

value = (1-t)(start) + (t)(end)

Meaning for this case:

value = (1 - OB)(OA) + (OB)(1)
      = (1 - 1/(2sqrt(2))(1/(2sqrt(2)) + (1/(2sqrt(2))(1)
      = (16 - 2sqrt(2))/(16sqrt(2))
      = approximates to ~0.58

Unfortunately, this shows that the method you developed is not a mathematical equivalent. (The value we should know at this time was 0.5.)


As with most game development tricks, I must emphasize that it looks good in practice and is more powerful than your alternatives (and there is no reason why you need to be mathematically accurate, for example if you use it for another mechanic) ). then go ahead.

There is a difference, but it is probably not significant. The best you can do is generate both and visually decide if the difference is worth the (potential) performance improvement.

If this is really a performance bottleneck (ie you've measured it), you may want to consider alternative techniques, such as: B. the simple pre-generation of the circle as a texture.

Note: If someone is able to explain pictures in words, for people with limited accessibility – please edit them. Unfortunately, I could not think of a meaningful description of the most important parts.

2d – How to draw a more uniform full circle?

I experiment with drawing circles and have forced a very simple one:



for y = 0 to d
  for x = 0 to d
    if (x-r)^2 + (y-r)^2 <= (r)^2
      plot(x+r, y+r, c)

The principle is simple. Step through each point in a square and draw every point that lies in the area of ​​the circle.

In the end, I have something like this:

Enter image description here

I do not want the single pixels to appear on every page. That's why I adapted this line from:

if (x-r)^2 + (y-r)^2 <= (r)^2


if (x-r)^2 + (y-r)^2 < (r)^2

In the end I have a circle like this:

Enter image description here

While this is a circle, it is not quite the circle that I want. The edges are too sharp and not convincingly inclined. Instead, I want to draw something smoother:

Enter image description here

But I'm not sure how to 'relax' the pixels to achieve this.

The code I posted is meant to illustrate how I draw the circle - I'm not looking for optimizations. I'm just interested in tweaking it to manipulate the smoothness of the drawn circle.

This is more than an adjustment for the last pixel along each page. I want something that scales with the size of the circle.

Complex integration $ e ^ {1 / z} $ over unit circle

I know how to do that with the Residue Theorem, but I do not know how to integrate it conceptually.

I have written $ e ^ {1 / z} = sum_ {n = 0} ^ { infty} frac {e ^ {- in theta}} {n!} $, and

int e ^ {1 / z} dz = sum_ {n = 0} ^ { infty} int_ {0} ^ {2 pi} frac {e ^ {- in theta}} {n!} ie ^ {i theta} d theta = sum_ {n = 0} ^ { infty} frac {i} {n!} int_ {0} ^ {2 pi} e ^ {(1-n ) i theta} d theta.

To let $ I = int_ {0} ^ {2 pi} e ^ {(1-n) i theta} d theta $. $ I = 0 $ that is the integral $ 0 $,

However, when I do the integral using the residual set, I get $ 2 pi i $, What is the problem?

Pygame: How do I control a sprite that moves in a circle?

So I write my own pygame code. In this game, two controllable "shields" (controllable sprites) orbiting a central block. Unfortunately, I do not really know how to glue these shields so they can only move around the middle block (left / a sends them clockwise, right / a sends them counterclockwise) and just make them behave like normal sprites not to move on a fixed path.
I do not have any code to display yet, but I can really appreciate some advice or best of all a few examples.

C # – Circle Area Application: Method does not show all paths in the code return value

I have a code that computes the circular area for three objects instantiated in AppCircle, but the getArea () method to return the circular area with the calculation, except that Visual Studio indicates that not all code paths return a value, Reporting error CS0116, which I do not understand.

using static System.Console;

namespace Aplicacao1
    public class Circulo
        private double raio;
        private double area;

        public double getRaio()
            return this.raio;

        public void setRaio(double raio)
            this.raio = raio;

        public double getArea()
            Circulo circulo1 = this;
            Circulo circulo2 = this;
            Circulo circulo3 = this;
            circulo1.area = 3.14159 * (raio * raio);
            circulo2.area = 3.14159 * (raio * raio);
            circulo3.area = 3.14159 * (raio * raio);

        public string toString()
            return raio + " " + area + " ";
using static System.Console;

namespace Aplicação1
    public class AppCirculo
        static int Main(string() args)
            Circulo circulo1 = new Circulo();
            Circulo circulo2 = new Circulo();
            Circulo circulo3 = new Circulo();

            Write("Digite o raio do círculo 1: ");

            Write("Digite o raio do círculo 2: ");

            Write("Digite o raio do círculo 3: ");

            return 0;

To delete the previous marker / circle / etc, before adding a new one

Pretty basic question, but I can not find the answer; I have an interactive map that stores coordinates for a click event. I want the old tags to be hidden when the user clicks on a new part of the map.

I've tried different things that include lists, and if commands are not cubes, I've read about "reactive" elements, not sure how to implement them. Examples that I tried did not work. Every advice appreciated.

Library (glossy)
Library (leaflet)

shinyApp (
ui = fluidPage (
leafletOutput ("Map")

Server <function (input, output, session) {

#initial map output
output$map <- renderLeaflet({
  leaflet() %>% 
    setView(lng =  -6.670972, lat =  54.693751, zoom=12) %>%
    addTiles(options = providerTileOptions(noWrap = TRUE)) %>%
}) #end render

observeEvent(input$map_click, {
    click <- input$map_click
    print(paste0(click$lat,", ",click$lng))
    x<-data.frame(col=paste0(click$lat,", ",click$lng))
    write.csv(x,"C:/test.csv", row.names = FALSE, quote = TRUE)
    leafletProxy('map') %>%
      addMarkers(lng=click$lng, lat=click$lat, label = paste0(round(click$lat,5),", ",round(click$lng,5)),labelOptions = labelOptions(noHide = T)) %>%
      addCircles(lng=click$lng, lat=click$lat, group='circles', weight=1, radius=300, color='black', fillColor='red',fillOpacity=0.2, opacity=1)
}) #end observe

}) #end app

The above code works, but creates a new marker each time

Algorithms – Determine the number of self-intersections for an irregular alignment of an n-pointed star whose vertices are at the boundary of a circle

I need to create an algorithm that returns the number of self-intersections for an irregular alignment of an n-pointed star whose vertices are at the boundary of a circle. The example input is as follows:


If the first integer is n (the number of vertices), n rows are continued, each describing the positions of the vertices that make up the star. Each vertex is at a unique position at the boundary of the unit circle, expressed in degrees from the normal axis. All degrees are in the range (0.360).

The sample output for example input would be:

5 crossings

To address this problem, I have considered subdividing the unit circle into quadrants and determining if there are intersections that depend on the locations of vertices in their respective quadrants. However, there was no way to do this.

I was wondering if maybe someone could deliver a high-level idea or a push in the right direction that could help me find an algorithm.


Circle Markets – www.circlemarkets.com – Forex Brokers

Founded in 2016, circle markets offers foreign exchange traders a high quality trading environment.

With Circle Markets, you can trade in one of 144 different currency pairs, in 7 different commodity markets, in one of 10 world-leading stock market indices, and in cryptocurrencies.

We provide easy-to-use account management tools that let you easily manage your accounts as a professional trader, account manager, or investor.

Circle Markets provides access to the MetaTrader 4 trading platform. This platform contains a number of technical analysis tools. Allows you to trade from your smartphone, tablet or PC. Gives you access to the latest financial news and market analysis as well as the connection to the interbank market.