graphics

C# graphics drawlines draws broken lines

只愿长相守 提交于 2021-02-20 04:28:09
问题 I am drawing ECG graphs using C# Graphics. I draw the curve using drawlines method. however line joints look broken. I tried all available options of smoothing mode and capstyle, none helps. here is sample graph1 and sample graph2 code is below: private void DrawCurve(Graphics g, cPoint[] data) { List<Point> ps = new List<Point>(); for (int i = 0; i < data.Length - 1; i++) { int x = data[i].x; int y = data[i].y; if (x > 0 && x < (Width)) { ps.Add(new Point(x, y)); } else if (x > Width) {

How do I call a function with a graphics object from another class?

断了今生、忘了曾经 提交于 2021-02-20 03:59:28
问题 I want to call paint() from main() but I need a parameter.I don't know which parameter to pass and I can't seem to use the Graphics object when I define g outside the parameters since it can't be initialized. I tried creating an object of the Graphics class in main() and then passing it as a parameter but then whenever I try to use g it gies me a nullException import java.util.*; import java.awt.*; import javax.swing.JFrame; class Boards extends Canvas { JFrame frame; void frame() { JFrame

Filling a polygon

妖精的绣舞 提交于 2021-02-19 08:44:17
问题 I created this function that draws a simple polygon with n number of vertexes: void polygon (int n) { double pI = 3.141592653589; double area = min(width / 2, height / 2); int X = 0, Y = area - 1; double offset = Y; int lastx, lasty; double radius = sqrt(X * X + Y * Y); double quadrant = atan2(Y, X); int i; for (i = 1; i <= n; i++) { lastx = X; lasty = Y; quadrant = quadrant + pI * 2.0 / n; X = round((double)radius * cos(quadrant)); Y = round((double)radius * sin(quadrant)); setpen((i * 255)

How to perform Boolean operation on thin surface using libigl?

为君一笑 提交于 2021-02-19 08:17:11
问题 I am currently working on libigl, and trying to grab the part of the a surface which locates inside another body. However, it seems than libigl only works with closed bodies: Here is the code which works for closed bodies. VA , VF is a triangular prism and VB , FB is a tetrahedron: #include <igl/readOFF.h> //#define IGL_NO_CORK //#undef IGL_STATIC_LIBRARY #include <igl/copyleft/cgal/mesh_boolean.h> #include <igl/viewer/Viewer.h> #include <Eigen/Core> #include <iostream> Eigen::MatrixXd VA,VB

How to determine when Rectangles overlap or intersect?

Deadly 提交于 2021-02-19 07:18:31
问题 I found out how to draw Rectangles and some code to find when two rectangles overlap but I can't connect these procedures. I have the two rectangles that I wanted but then a cannot determine whether these intersect, to then add this information to a ListBox. Here is my code: public partial class Form1 : Form { Graphics g; Pen p; Point cursor; int k = 0; Point[] tocke = new Point[2]; public Form1() { InitializeComponent(); g = this.CreateGraphics(); p = new Pen(Color.Black, 3); } private void

Sub-pixel Image rendering

霸气de小男生 提交于 2021-02-19 06:39:07
问题 I am aware of sub-pixel shapes, such as Rectangle2D.Double , Ellipse2D.Double and Line2D.Double - but I couldn't find information about drawing an Image / BufferedImage with sub-pixel accuracy. Perhaps something that would look like this - Image2D.Double ? Is there any way I can achieve this? 回答1: Images may be drawn with an AffineTransform, which can specify scaling and translation with floating point values. (See drawImage(Image, AffineTransform, ImageObserver) method) For example, to draw

How to draw a line dynamically in Android layout

China☆狼群 提交于 2021-02-19 03:42:08
问题 What I have done: What I am looking for: I do not care about design, but I do not know how to connect buttons to Main button with lines that are similar to the second image. Note: I am creating buttons dynamically. Thus, I do not use XML file as I do not know how many lines/buttons I will have. protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.second_layout); // RelativeLayout FirstLayout = (RelativeLayout)findViewById(R.id.second

Why is origin usually top left corner in painting APIs when logically and native GL is at bottom left corner?

情到浓时终转凉″ 提交于 2021-02-18 17:10:44
问题 I notice that a lot of drawing APIs have their 0,0 origin at the top left corner, so y actually goes down as it increases. I wonder why is that? Any particular advantage to not working in what I personally consider to be more logical bottom left corner (the origin of a regular x/y grid), which also happens to be the native representation of coordinates in hardware rendering APIs? Or maybe it has something to do with the way scanline rendering or even display refresh goes? 回答1: 2D raster

Ray Cylinder intersection

£可爱£侵袭症+ 提交于 2021-02-18 08:23:08
问题 I am developing a Ray Tracing system and it is working, now I am trying to support more primitives (for now it supports: spheres, boxes, planes and triangles), and I am having problems with cylinders. I know to intersect ray with cylinder I need to do two check, the first is with the body (with that I get an Infinite Cylinder), for this I assume circle in two dimensions, in the plane xz (x² + z² = r, where r is the radius) then I need check that Y coordinate is between 0 and height and

Java how does graphics abstract drawline method really works?

旧时模样 提交于 2021-02-17 02:00:35
问题 I read source code of Java Graphics abstract class, I am curious how does this abstract void drawline method draws lines in JComponent's paint(Graphics g) and paintComponent(Graphics g). I know that abstract methods have no method body. I couldn't find any relevant examples with Google. If possible, can you provide me a link to source code of this method. 回答1: Mad Programmer is right, all of java's graphics and graphics2d methods is directed with native codes. If you're curious about these