Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

c# get every point in a line in matrix

public class Line {
    public Point p1, p2;

    public Line(Point p1, Point p2) {
        this.p1 = p1;
        this.p2 = p2;
    }

    public Point[] getPoints(int quantity) {
        var points = new Point[quantity];
        int ydiff = p2.Y - p1.Y, xdiff = p2.X - p1.X;
        double slope = (double)(p2.Y - p1.Y) / (p2.X - p1.X);
        double x, y;

        --quantity;

        for (double i = 0; i < quantity; i++) {
            y = slope == 0 ? 0 : ydiff * (i / quantity);
            x = slope == 0 ? xdiff * (i / quantity) : y / slope;
            points[(int)i] = new Point((int)Math.Round(x) + p1.X, (int)Math.Round(y) + p1.Y);
        }

        points[quantity] = p2;
        return points;
    }
}
Comment

PREVIOUS NEXT
Code Example
Csharp :: exe path c# 
Csharp :: how to detect ajax request in asp.net core 
Csharp :: cache trong mvc 
Csharp :: how to create a blazor client-side application in a command-line interface 
Csharp :: unity apply bloom of a different color 
Csharp :: c# internalsvisibleto 
Csharp :: C# show text in another form 
Csharp :: only specific columns in Linq 
Csharp :: invalidoperationexception c# ui thread 
Csharp :: c# check port in remote pc 
Csharp :: how to round to nearest number in array c# 
Csharp :: c# mongodb count documents 
Csharp :: how to get length of okobjectresult c# 
Csharp :: c# press ctrl and alt 
Csharp :: remove substring from string c# 
Csharp :: how to iterate a generic list in c# 
Csharp :: encode pdf file to base64 c# 
Csharp :: c# resize multidimensional array 
Csharp :: check if element in hashset c# 
Csharp :: how to instantiate and delete unity 
Csharp :: unity find deactivated gameobject 
Csharp :: how to jump in unity using physics 
Csharp :: how to display a form when a button click c# windows form 
Csharp :: c# define array 
Csharp :: c# square symbol 
Csharp :: triangle 
Csharp :: c# webclient vs httpclient 
Csharp :: Entity framwork update parent entity added new sub entity 
Csharp :: for loop c# to print times tables 
Csharp :: c# insert today datetime 
ADD CONTENT
Topic
Content
Source link
Name
1+3 =