NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

import javax.media.opengl.GL2;
import javax.media.opengl.GLAutoDrawable;
import javax.media.opengl.GLEventListener;
import javax.media.opengl.glu.GLU;

public class MidPointLines implements GLEventListener {
/**
* Interface to the GLU library.
*/
private GLU glu;

/**
* Take care of initialization here.
* @param gld
*/
@Override
public void init(GLAutoDrawable gld) {
GL2 gl = gld.getGL().getGL2();
glu = new GLU();

gl.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
gl.glViewport(-250, -150, 250, 150);
gl.glMatrixMode(GL2.GL_PROJECTION);
gl.glLoadIdentity();
glu.gluOrtho2D(-250.0, 250.0, -150.0, 150.0);
}

/**
* Take care of drawing here.
* @param drawable
*/
@Override
public void display(GLAutoDrawable drawable) {
GL2 gl = drawable.getGL().getGL2();

gl.glClear(GL2.GL_COLOR_BUFFER_BIT);
/*
* put your code here
*/
//points should be in the same zone
DrawMPL(gl,10,10,60,50);
DrawMPL(gl,10,-10,60,-50);
DrawMPL(gl,-30,-10,-100,-40);

}

@Override
public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) {
//do nothing
}

public void displayChanged(GLAutoDrawable drawable, boolean modeChanged, boolean deviceChanged) {
//do nothing
}

float dx, dy, b;
private void DrawMPL(GL2 gl, float x1, float y1, float x2, float y2) {
gl.glPointSize(3.0f);
gl.glColor3d(1, 0, 0);
float x,y,dx,dy,d,dE,dNE;
float zone=findZone(x1, y1, x2,y2);
float x1new=convertX0( x1, y1, zone);
float x2new=convertX0( x2, y2, zone);
float y1new=convertY0( x1, y1, zone);
float y2new=convertY0( x2, y2, zone);

dx=x2new-x1new;
dy=y2new-y1new;
dE=dy;
dNE=dy-dx;
d=dy-(dx/2);
x=x1new;
y=y1new;



gl.glBegin(GL2.GL_POINTS);


gl.glVertex2f(x1, y1);
gl.glVertex2f(x2, y2);

while(x<x2new)
{
if(d<0)
{
x++;
d+=dE;
gl.glVertex2f(convertXi( x, y, zone),convertYi( x, y, zone));
}
else {
x++;
y++;
d+=dNE;
gl.glVertex2f(convertXi( x, y, zone),convertYi( x, y, zone));
}
}


gl.glEnd();
}

//y=mx+b
private float func(float x, float y){
return (float)(dy*x - y*dx + b*dx);
}


float findZone(float x1, float y1, float x2, float y2) {
float Zone=0;
float dx=x2-x1;
float dy=y2-y1;
if (Math.abs(dx)>=Math.abs(dy)){
if(dx>0 && dy>0)
Zone=0;
if(dx<0 && dy>0)
Zone=3;
if(dx<0 && dy<0)
Zone=4;
if(dx>0 && dy<0)
Zone=7;


}
else{
if(dx>0 && dy>0)
Zone=1;
if(dx<0 && dy>0)
Zone=2;
if(dx<0 && dy<0)
Zone=5;
if(dx>0 && dy<0)
Zone=6;
}
return Zone ;

}

float convertX0(float x, float y, float zone){
float xnew=0;

if(zone==0) {
xnew=x;
}else if(zone==1) {

xnew=y;
}else if(zone==2) {

xnew=y;
}else if(zone==3) {

xnew=-x;
}else if(zone==4) {

xnew=-x;
}else if(zone==5) {

xnew=-y;
}else if(zone==6) {

xnew=-y;
}else if(zone==7) {

xnew=x;
}
return xnew;


}

float convertY0(float x, float y, float zone){
float ynew=0;

if(zone==0) {
ynew=y;
}else if(zone==1) {

ynew=x;
}else if(zone==2) {

ynew=-x;
}else if(zone==3) {

ynew=y;
}else if(zone==4) {

ynew=-y;
}else if(zone==5) {

ynew=-x;
}else if(zone==6) {

ynew=x;
}else if(zone==7) {

ynew=-y;
}
return ynew;

}

float convertXi(float x, float y, float zone){
float xnew=0;

if(zone==0) {
xnew=x;
}else if(zone==1) {

xnew=y;
}else if(zone==2) {

xnew=-y;
}else if(zone==3) {

xnew=-x;
}else if(zone==4) {

xnew=-x;
}else if(zone==5) {

xnew=-y;
}else if(zone==6) {

xnew=y;
}else if(zone==7) {

xnew=x;
}
return xnew;


}

float convertYi(float x, float y, float zone){
float ynew=0;

if(zone==0) {
ynew=y;
}else if(zone==1) {

ynew=x;
}else if(zone==2) {

ynew=x;
}else if(zone==3) {

ynew=y;
}else if(zone==4) {

ynew=-y;
}else if(zone==5) {

ynew=-x;
}else if(zone==6) {

ynew=-x;
}else if(zone==7) {

ynew=-y;
}
return ynew;

}


public void dispose(GLAutoDrawable arg0) {
//do nothing
}

}

     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.